Documentation ¶
Overview ¶
Package provides basic routing functionality for flamingo
Index ¶
- Constants
- Variables
- func Bind(injector *dingo.Injector, m Module)
- type Action
- type ControllerOption
- type ControllerOptionAware
- type DataAction
- type EventRouterProvider
- type Filter
- type FilterChain
- type FilterProvider
- type Handler
- type Match
- type Module
- type OnFinishEvent
- type OnRequestEvent
- type OnResponseEvent
- type P
- type Path
- type Registry
- func (registry *Registry) Alias(name, to string)
- func (registry *Registry) GetRoutes() []*Handler
- func (registry *Registry) HandleAny(name string, action Action)
- func (registry *Registry) HandleData(name string, action DataAction)
- func (registry *Registry) HandleDelete(name string, action Action)
- func (registry *Registry) HandleGet(name string, action Action)
- func (registry *Registry) HandleHead(name string, action Action)
- func (registry *Registry) HandleMethod(method, name string, action Action)
- func (registry *Registry) HandleOptions(name string, action Action)
- func (registry *Registry) HandlePost(name string, action Action)
- func (registry *Registry) HandlePut(name string, action Action)
- func (registry *Registry) Has(method, name string) bool
- func (registry *Registry) HasAny(name string) bool
- func (registry *Registry) HasData(name string) bool
- func (registry *Registry) Reverse(name string, params map[string]string) (string, error)
- func (registry *Registry) Route(path, handler string) *Handler
- type RegistryProvider
- type Router
- func (router *Router) Base() *url.URL
- func (router *Router) Data(ctx context.Context, handler string, params map[interface{}]interface{}) interface{}
- func (router *Router) Init(routingConfig *config.Area) *Router
- func (router *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (router *Router) SetBase(u *url.URL)
- func (router *Router) TryURL(name string, params map[string]string) (u *url.URL, err error)
- func (router *Router) URL(name string, params map[string]string) *url.URL
Constants ¶
const ( // FlamingoError is the Controller name for errors FlamingoError = "flamingo.error" // FlamingoNotfound is the Controller name for 404 notfound FlamingoNotfound = "flamingo.notfound" // ERROR is used to bind errors to contexts ERROR errorKey = iota )
Variables ¶
var (
// ControllerKey exposes the current controller/handler key
ControllerKey, _ = tag.NewKey("controller")
)
Functions ¶
Types ¶
type Action ¶
Action defines an explicit http action
func HTTPAction ¶
HTTPAction wraps a default http.Handler to a flamingo router action
type ControllerOption ¶
type ControllerOption string
ControllerOption defines a type for Controller options todo still usable?
type ControllerOptionAware ¶
type ControllerOptionAware interface {
CheckOption(option ControllerOption) bool
}
ControllerOptionAware is an interface for Controller which want to interact with filter todo still usable?
type DataAction ¶
DataAction is a method called which does not return the web response itself, but data instead
type EventRouterProvider ¶
EventRouterProvider for event injection
type Filter ¶
type Filter interface {
Filter(ctx context.Context, r *web.Request, w http.ResponseWriter, fc *FilterChain) web.Response
}
Filter is an interface which can filter requests
type FilterChain ¶
type FilterChain struct {
Filters []Filter
}
FilterChain defines the chain which contains all filters which will be worked off
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler defines a concrete Controller
func (*Handler) GetHandlerName ¶
GetHandlerName getter
type Module ¶
type Module interface {
Routes(registry *Registry)
}
Module defines a router Module, which is able to register routes
type OnFinishEvent ¶
type OnFinishEvent struct { ResponseWriter http.ResponseWriter Request *http.Request Error error }
OnFinishEvent is the event object associated to OnFinish
type OnRequestEvent ¶
type OnRequestEvent struct { ResponseWriter http.ResponseWriter Request *http.Request }
OnRequestEvent contains the bare request
type OnResponseEvent ¶
type OnResponseEvent struct { Response web.Response Request *http.Request ResponseWriter http.ResponseWriter }
OnResponseEvent is the event associated to OnResponse
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path is a matchable routing path
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds a list of all routes and handlers to be registered in modules.
We have: routes: key-params -> path, for reverse routes
path: url-pattern -> key+params
Handler: key -> Controller
func (*Registry) HandleAny ¶
HandleAny serves as a fallback to handle HTTP requests which are not taken care of by other handlers
func (*Registry) HandleData ¶
func (registry *Registry) HandleData(name string, action DataAction)
HandleData sets the controllers data action
func (*Registry) HandleDelete ¶
HandleDelete handles HTTP DELETE requests
func (*Registry) HandleHead ¶
HandleHead handles HTTP HEAD requests
func (*Registry) HandleMethod ¶
HandleMethod handles requests for the specified HTTP Method
func (*Registry) HandleOptions ¶
HandleOptions handles HTTP OPTIONS requests
func (*Registry) HandlePost ¶
HandlePost handles HTTP POST requests
type RegistryProvider ¶
type RegistryProvider func() []Module
RegistryProvider is called to retrieve registered routes
type Router ¶
type Router struct { Sessions sessions.Store `inject:",optional"` // Sessions storage, which are used to retrieve user-context session SessionName string `inject:"config:session.name"` EventRouterProvider EventRouterProvider `inject:""` Injector *dingo.Injector `inject:""` RouterRegistryProvider RegistryProvider `inject:""` RouterRegistry *Registry `inject:""` RouterTimeout float64 `inject:"config:flamingo.router.timeout"` NotFoundHandler string `inject:"config:flamingo.router.notfound"` ErrorHandler string `inject:"config:flamingo.router.error"` FilterProvider FilterProvider `inject:",optional"` // contains filtered or unexported fields }
Router defines the basic Router which is used for holding a context-scoped setup This includes DI resolving etc
func (*Router) Data ¶
func (router *Router) Data(ctx context.Context, handler string, params map[interface{}]interface{}) interface{}
Data calls a flamingo data controller
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP shadows the internal mux.Router's ServeHTTP to defer panic recoveries and logging.