api

package
v0.0.0-...-3de62b2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Path of the api to serve files
	Path = os.Getenv("STATIC_PWD")

	// D api to communicate with datasctore
	D data.Data

	// Logger used to log output
	Logger = log.New(os.Stdout, "Api: ", log.Ldate|log.Ltime|log.Lshortfile)

	// FunctionsWithToken List all api functions that does require a token
	FunctionsWithToken = []Func{
		NewFunc(umanagement.UpdateToken, "/updatetoken"),
		NewFunc(umanagement.Delete, "/delete"),
		NewFunc(store.AddStore, "/store/add"),
		NewFunc(store.GetStore, "/store/get"),
		NewFunc(store.ScoreStore, "/store/score"),
		NewFunc(store.DeleteStore, "/store/delete"),
		NewFunc(store.UpdateStore, "/store/update"),
		NewFunc(consumables.Store, "/consumable/add"),
		NewFunc(consumables.Get, "/consumable/get"),
		NewFunc(list.AddList, "/list/create"),
		NewFunc(list.GetLists, "/list/getall"),
		NewFunc(list.GetListContent, "/list/getcontent"),
		NewFunc(list.AddPersonnal, "/list/add/personnal"),
		NewFunc(list.AddConsumable, "/list/add/consumable"),
	}
	// Functions List all api functions that does not require a token
	Functions = []Func{
		NewFunc(global.Log, "/log"),
		NewFunc(umanagement.Login, "/login"),
		NewFunc(umanagement.Register, "/register"),
		NewFunc(verify.Email, "/verify/email"),
		NewFunc(verify.Password, "/verify/password"),
	}

	// SFiles is stored informations on special files
	SFiles = []File{
		NewSFile("js/eiko/eiko-sw.js", "application/javascript", []string{"/eiko-sw.js"}),
		NewSFile("img/EIKO.ico", "image/vnd.microsoft.icon", []string{"/favicon.ico", "/EIKO.ico"}),
		NewSFile("json/manifest.json", "application/json", []string{"/manifest.json", "/json/manifest.json"}),
		NewSFile("json/autocomplete_data.json", "application/json", []string{"/json/autocomplete_data.json"}),
	}

	// TFiles is an array of Templated files
	TFiles = []File{
		NewFile("html/eiko.html", "text/html", "Acceuil", []string{"/eiko.html", "/", "/index.html", "/l/:id"}),
		NewFile("html/login.html", "text/html", "Connexion", []string{"/login.html"}),
		NewFile("html/search.html", "text/html", "Recherche", []string{"/search/", "/search.html"}),
	}
)

Functions

func ExecuteAPI

func ExecuteAPI() *httprouter.Router

ExecuteAPI Execute the api and return the bdd configured.

func InitAPI

func InitAPI() *httprouter.Router

InitAPI Execute the api and return the bdd configured.

func ServeFiles

func ServeFiles(r *httprouter.Router)

ServeFiles adds to a Router special files URLs to be served. It also adds all static files to the Router

func ServeFilesCustom

func ServeFilesCustom(router *httprouter.Router, urlpath, filepath string)

ServeFilesCustom TODO

Types

type File

type File struct {
	// Path of the file to serve
	Path string
	// CType AKA Content-type
	CType string
	// URLs of the served file
	URL []string
	// Title page title
	Title string
	//  User Current user
	User structures.User
}

File is used to link the special file path with the URL to serve

func NewFile

func NewFile(path, ct, title string, url []string) File

NewFile return a new File struct

func NewSFile

func NewSFile(path, ct string, url []string) File

NewSFile return a new spacial File struct

func (File) SpecialFiles

func (file File) SpecialFiles(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params)

SpecialFiles simple html file server

func (File) TemplatedFiles

func (file File) TemplatedFiles(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params)

TemplatedFiles simple html file server (wapper for TemplatedFilesWrapped)

func (File) TemplatedFilesWrapped

func (file File) TemplatedFilesWrapped(w http.ResponseWriter,
	r *http.Request) error

TemplatedFilesWrapped simple html file server

type Func

type Func struct {
	// Function is the function wrapped
	Function func(data.Data, *http.Request) (string, error)
	// Path is the path on with you want to call the function from the api
	Path string
}

Func is used to call the Function with the wrapper

func NewFunc

func NewFunc(function func(data.Data, *http.Request) (string, error), path string) Func

NewFunc return a new Func struct

func (Func) WrapperFunction

func (fun Func) WrapperFunction(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params)

WrapperFunction allows us to call the functions with rights args. Db must be set already.

func (Func) WrapperFunctionCookie

func (fun Func) WrapperFunctionCookie(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params)

WrapperFunctionCookie allows us to call the functions with rights args. Db must be set already. Read Token cookie and set the User value of D

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL