Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRouteStringFormat is returned when the route string is of the wrong format ErrRouteStringFormat = errors.New("wrong route string, example is\" get,post;/hello/world;Hello\"") )
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
type Middleware struct { Type MiddlewareType // contains filtered or unexported fields }
Middleware is the utron middleware
type MiddlewareType ¶
type MiddlewareType int
MiddlewareType is the kind of middleware. Utron support middleware with variary of signatures.
const ( //PlainMiddleware is the middleware with signature // func(http.Handler)http.Handler PlainMiddleware MiddlewareType = iota //CtxMiddleware is the middlewate with signature // func(*base.Context)error CtxMiddleware )
type Options ¶
type Options struct { Model *models.Model View view.View Config *config.Config Log logger.Logger SessionStore sessions.Store }
Options additional settings for the router.
type Router ¶
Router registers routes and handlers. It embeds gorilla mux Router
func (*Router) Add ¶
func (r *Router) Add(ctrlfn func() controller.Controller, middlewares ...interface{}) error
Add registers ctrl. It takes additional comma separated list of middleware. middlewares are of type
func(http.Handler)http.Handler or func(*base.Context)error
utron uses the alice package to chain middlewares, this means all alice compatible middleware works out of the box
func (*Router) LoadRoutes ¶
LoadRoutes searches for the route file i the cfgPath. The order of file lookup is as follows.
- routes.json
- routes.toml
- routes.yml
- routes.hcl
func (*Router) LoadRoutesFile ¶
LoadRoutesFile loads routes from a json file. Example of the routes file.
{ "routes": [ "get,post;/hello;Sample.Hello", "get,post;/about;Hello.About" ] }
supported formats are json, toml, yaml and hcl with extension .json, .toml, .yml and .hcl respectively.
TODO refactor the decoding part to a separate function? This part shares the same logic as the one found in NewConfig()