Documentation ¶
Index ¶
- Constants
- Variables
- func BindRoutes(injector *dingo.Injector, m RoutesModule)
- func ContextWithRequest(ctx context.Context, r *Request) context.Context
- func ContextWithSession(ctx context.Context, session *Session) context.Context
- func HandlerCmd(router *Router, area *config.Area) *cobra.Command
- func RoutesCmd(router *Router, area *config.Area) *cobra.Command
- func URLTitle(title string) string
- type Action
- type DataAction
- type DataResponse
- type EventRouterProvider
- type Filter
- type FilterChain
- type FilterProvider
- type GetPartialDataFunc
- type Handler
- type Match
- type OnFinishEvent
- type OnRequestEvent
- type OnResponseEvent
- type Path
- type RegistryProvider
- type RenderResponse
- type Request
- func (r *Request) Form(name string) ([]string, error)
- func (r *Request) Form1(name string) (string, error)
- func (r *Request) FormAll() (map[string][]string, error)
- func (r *Request) Query(name string) ([]string, error)
- func (r *Request) Query1(name string) (string, error)
- func (r *Request) QueryAll() url.Values
- func (r *Request) RemoteAddress() []string
- func (r *Request) Request() *http.Request
- func (r *Request) Session() *Session
- type RequestParams
- type Responder
- func (r *Responder) Data(data interface{}) *DataResponse
- func (r *Responder) Download(data io.ReadCloser, contentType string, fileName string, forceDownload bool) *Response
- func (r *Responder) Forbidden(err error) *ServerErrorResponse
- func (r *Responder) HTTP(status uint, body io.Reader) *Response
- func (r *Responder) Inject(engine flamingo.TemplateEngine, router *Router, cfg ...) *Responder
- func (r *Responder) NotFound(err error) *ServerErrorResponse
- func (r *Responder) Render(tpl string, data interface{}) *RenderResponse
- func (r *Responder) RouteRedirect(to string, data map[string]string) *RouteRedirectResponse
- func (r *Responder) ServerError(err error) *ServerErrorResponse
- func (r *Responder) ServerErrorWithCodeAndTemplate(err error, tpl string, status uint) *ServerErrorResponse
- func (r *Responder) TODO() *Response
- func (r *Responder) URLRedirect(url *url.URL) *URLRedirectResponse
- func (r *Responder) Unavailable(err error) *ServerErrorResponse
- type Response
- type Result
- type RouteRedirectResponse
- 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) Inject(eventRouterProvider EventRouterProvider, injector *dingo.Injector, ...) *Router
- func (router *Router) ServeHTTP(rw http.ResponseWriter, httpRequest *http.Request)
- func (router *Router) SetBase(u *url.URL)
- func (router *Router) URL(name string, params map[string]string) (*url.URL, error)
- type RouterRegistry
- func (registry *RouterRegistry) Alias(name, to string)
- func (registry *RouterRegistry) GetRoutes() []*Handler
- func (registry *RouterRegistry) HandleAny(name string, action Action)
- func (registry *RouterRegistry) HandleData(name string, action DataAction)
- func (registry *RouterRegistry) HandleDelete(name string, action Action)
- func (registry *RouterRegistry) HandleGet(name string, action Action)
- func (registry *RouterRegistry) HandleHead(name string, action Action)
- func (registry *RouterRegistry) HandleMethod(method, name string, action Action)
- func (registry *RouterRegistry) HandleOptions(name string, action Action)
- func (registry *RouterRegistry) HandlePost(name string, action Action)
- func (registry *RouterRegistry) HandlePut(name string, action Action)
- func (registry *RouterRegistry) Has(method, name string) bool
- func (registry *RouterRegistry) HasAny(name string) bool
- func (registry *RouterRegistry) HasData(name string) bool
- func (registry *RouterRegistry) Reverse(name string, params map[string]string) (string, error)
- func (registry *RouterRegistry) Route(path, handler string) (*Handler, error)
- type RoutesModule
- type ServerErrorResponse
- type Session
- func (s *Session) AddFlash(value interface{}, vars ...string)
- func (s *Session) ClearAll() *Session
- func (s *Session) Delete(key interface{})
- func (s *Session) Flashes(vars ...string) []interface{}
- func (s *Session) ID() (id string)
- func (s *Session) Keys() []interface{}
- func (s *Session) Load(key interface{}) (data interface{}, ok bool)
- func (s *Session) Store(key interface{}, data interface{}) *Session
- func (s *Session) Try(key interface{}) (data interface{})
- type SetPartialDataFunc
- type URLRedirectResponse
Examples ¶
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 // deprecated fix ERROR errorKey = iota )
Variables ¶
var ( // ErrFormNotFound is returned for unknown form values ErrFormNotFound = errors.New("form value not found") // ErrQueryNotFound is returned for unknown URL query parameters ErrQueryNotFound = errors.New("query value not found") )
var (
// ControllerKey exposes the current controller/handler key
ControllerKey, _ = tag.NewKey("controller")
)
Functions ¶
func BindRoutes ¶
func BindRoutes(injector *dingo.Injector, m RoutesModule)
BindRoutes is a convenience helper to multi-bind router modules
func ContextWithRequest ¶
ContextWithRequest stores the request in a new context
func ContextWithSession ¶
ContextWithSession returns a new Context with an attached session
func HandlerCmd ¶
HandlerCmd for debugging the router/handler configuration
Types ¶
type Action ¶
Action defines an explicit http action
func WrapDataAction ¶
func WrapDataAction(da DataAction) Action
WrapDataAction allows to register a data action for a HTTP method
func WrapHTTPHandler ¶
WrapHTTPHandler wraps an http.Handler to be used in the flamingo http package
type DataAction ¶
type DataAction func(ctx context.Context, req *Request, callParams RequestParams) interface{}
DataAction is a method called which does not return the web response itself, but data instead
type DataResponse ¶
type DataResponse struct { Response Data interface{} }
DataResponse returns a response containing data, e.g. as JSON
func (*DataResponse) Apply ¶
func (r *DataResponse) Apply(c context.Context, w http.ResponseWriter) error
Apply response todo: support more than json
func (*DataResponse) Status ¶
func (r *DataResponse) Status(status uint) *DataResponse
Status - changes status in the response
type EventRouterProvider ¶
type EventRouterProvider func() flamingo.EventRouter
EventRouterProvider for event injection
type Filter ¶
type Filter interface {
Filter(ctx context.Context, r *Request, w http.ResponseWriter, fc *FilterChain) Result
}
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
func (*FilterChain) Next ¶
func (fc *FilterChain) Next(ctx context.Context, r *Request, w http.ResponseWriter) Result
Next calls the next filter and deletes it of the chain
type GetPartialDataFunc ¶
type GetPartialDataFunc struct{}
GetPartialDataFunc allows to get partial data
func (*GetPartialDataFunc) Func ¶
func (*GetPartialDataFunc) Func(c context.Context) interface{}
Func getter to bind the context
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler defines a concrete Controller
func (*Handler) GetHandlerName ¶
GetHandlerName getter
type OnFinishEvent ¶
type OnFinishEvent struct { OnRequestEvent Error error }
OnFinishEvent is the event object associated to OnFinish
type OnRequestEvent ¶
type OnRequestEvent struct { Request *Request ResponseWriter http.ResponseWriter }
OnRequestEvent contains the bare request
type OnResponseEvent ¶
type OnResponseEvent struct { OnRequestEvent Result Result }
OnResponseEvent is the event associated to OnResponse
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path is a matchable routing path
type RegistryProvider ¶
type RegistryProvider func() []RoutesModule
RegistryProvider is called to retrieve registered routes
type RenderResponse ¶
type RenderResponse struct { DataResponse Template string // contains filtered or unexported fields }
RenderResponse renders data
func (*RenderResponse) Apply ¶
func (r *RenderResponse) Apply(c context.Context, w http.ResponseWriter) error
Apply response
type Request ¶
type Request struct { Params RequestParams Values sync.Map // contains filtered or unexported fields }
Request object stores the actual HTTP Request, Session, Params and attached Values
func CreateRequest ¶
CreateRequest creates a new request, with optional http.Request and Session. If any variable is nil it is ignored, otherwise it is copied into the new Request.
func RequestFromContext ¶
RequestFromContext retrieves the request from the context, if available
func (*Request) RemoteAddress ¶
RemoteAddress get the requests real remote address
type RequestParams ¶
RequestParams store string->string values for request data
type Responder ¶
type Responder struct {
// contains filtered or unexported fields
}
Responder generates responses
func (*Responder) Data ¶
func (r *Responder) Data(data interface{}) *DataResponse
Data returns a data response which can be serialized
func (*Responder) Download ¶
func (r *Responder) Download(data io.ReadCloser, contentType string, fileName string, forceDownload bool) *Response
Download returns a download response to handle file downloads
func (*Responder) Forbidden ¶
func (r *Responder) Forbidden(err error) *ServerErrorResponse
Forbidden creates a 403 error response
func (*Responder) Inject ¶
func (r *Responder) Inject(engine flamingo.TemplateEngine, router *Router, cfg *struct { TemplateForbidden string `inject:"config:flamingo.template.err403"` TemplateNotFound string `inject:"config:flamingo.template.err404"` TemplateUnavailable string `inject:"config:flamingo.template.err503"` TemplateErrorWithCode string `inject:"config:flamingo.template.errWithCode"` }) *Responder
Inject Responder dependencies
func (*Responder) NotFound ¶
func (r *Responder) NotFound(err error) *ServerErrorResponse
NotFound creates a 404 error response
func (*Responder) Render ¶
func (r *Responder) Render(tpl string, data interface{}) *RenderResponse
Render creates a render response, with the supplied template and data
func (*Responder) RouteRedirect ¶
func (r *Responder) RouteRedirect(to string, data map[string]string) *RouteRedirectResponse
RouteRedirect generator
func (*Responder) ServerError ¶
func (r *Responder) ServerError(err error) *ServerErrorResponse
ServerError creates a 500 error response
func (*Responder) ServerErrorWithCodeAndTemplate ¶
func (r *Responder) ServerErrorWithCodeAndTemplate(err error, tpl string, status uint) *ServerErrorResponse
ServerErrorWithCodeAndTemplate error response with template and http status code
func (*Responder) URLRedirect ¶
func (r *Responder) URLRedirect(url *url.URL) *URLRedirectResponse
URLRedirect returns a 303 redirect to a given URL
func (*Responder) Unavailable ¶
func (r *Responder) Unavailable(err error) *ServerErrorResponse
Unavailable creates a 503 error response
type Result ¶
type Result interface { // Apply executes the response on the http.ResponseWriter Apply(ctx context.Context, rw http.ResponseWriter) error }
Result defines the generic web response
type RouteRedirectResponse ¶
type RouteRedirectResponse struct { Response To string Data map[string]string // contains filtered or unexported fields }
RouteRedirectResponse redirects to a certain route
func (*RouteRedirectResponse) Apply ¶
func (r *RouteRedirectResponse) Apply(c context.Context, w http.ResponseWriter) error
Apply response
func (*RouteRedirectResponse) Permanent ¶
func (r *RouteRedirectResponse) Permanent() *RouteRedirectResponse
Permanent marks a redirect as being permanent (http 301)
type Router ¶
type Router struct {
// 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) Inject ¶
func (router *Router) Inject( eventRouterProvider EventRouterProvider, injector *dingo.Injector, routerRegistryProvider RegistryProvider, routerRegistry *RouterRegistry, cfg *struct { SessionName string `inject:"config:session.name"` SessionStore sessions.Store `inject:",optional"` 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"` }, ) *Router
Inject dependencies
type RouterRegistry ¶
type RouterRegistry struct {
// contains filtered or unexported fields
}
RouterRegistry 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 (*RouterRegistry) Alias ¶
func (registry *RouterRegistry) Alias(name, to string)
Alias for an existing router definition
func (*RouterRegistry) GetRoutes ¶
func (registry *RouterRegistry) GetRoutes() []*Handler
GetRoutes returns registered Routes
func (*RouterRegistry) HandleAny ¶
func (registry *RouterRegistry) HandleAny(name string, action Action)
HandleAny serves as a fallback to handle HTTP requests which are not taken care of by other handlers
func (*RouterRegistry) HandleData ¶
func (registry *RouterRegistry) HandleData(name string, action DataAction)
HandleData sets the controllers data action
func (*RouterRegistry) HandleDelete ¶
func (registry *RouterRegistry) HandleDelete(name string, action Action)
HandleDelete handles HTTP DELETE requests
func (*RouterRegistry) HandleGet ¶
func (registry *RouterRegistry) HandleGet(name string, action Action)
HandleGet handles a HTTP GET request
func (*RouterRegistry) HandleHead ¶
func (registry *RouterRegistry) HandleHead(name string, action Action)
HandleHead handles HTTP HEAD requests
func (*RouterRegistry) HandleMethod ¶
func (registry *RouterRegistry) HandleMethod(method, name string, action Action)
HandleMethod handles requests for the specified HTTP Method
func (*RouterRegistry) HandleOptions ¶
func (registry *RouterRegistry) HandleOptions(name string, action Action)
HandleOptions handles HTTP OPTIONS requests
func (*RouterRegistry) HandlePost ¶
func (registry *RouterRegistry) HandlePost(name string, action Action)
HandlePost handles HTTP POST requests
func (*RouterRegistry) HandlePut ¶
func (registry *RouterRegistry) HandlePut(name string, action Action)
HandlePut handles HTTP PUT requests
func (*RouterRegistry) Has ¶
func (registry *RouterRegistry) Has(method, name string) bool
Has checks if a method is set for a given handler name
func (*RouterRegistry) HasAny ¶
func (registry *RouterRegistry) HasAny(name string) bool
HasAny checks if an any handler is set for a given name
func (*RouterRegistry) HasData ¶
func (registry *RouterRegistry) HasData(name string) bool
HasData checks if a data handler is set for a given name
type RoutesModule ¶
type RoutesModule interface {
Routes(registry *RouterRegistry)
}
RoutesModule defines a router RoutesModule, which is able to register routes
type ServerErrorResponse ¶
type ServerErrorResponse struct { RenderResponse Error error }
ServerErrorResponse returns a server error, by default http 500
func (*ServerErrorResponse) Apply ¶
func (r *ServerErrorResponse) Apply(c context.Context, w http.ResponseWriter) error
Apply response
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds the data connected to the current user session
func EmptySession ¶
func EmptySession() *Session
EmptySession creates an empty session instance for testing etc.
func SessionFromContext ¶
SessionFromContext allows to retrieve the stored session
func (*Session) Delete ¶
func (s *Session) Delete(key interface{})
Delete a given key from the session
func (*Session) Keys ¶
func (s *Session) Keys() []interface{}
Keys returns an unordered list of session keys
type SetPartialDataFunc ¶
type SetPartialDataFunc struct{}
SetPartialDataFunc allows to set partial data
func (*SetPartialDataFunc) Func ¶
func (*SetPartialDataFunc) Func(c context.Context) interface{}
Func getter to bind the context
type URLRedirectResponse ¶
URLRedirectResponse redirects to a certain URL
func (*URLRedirectResponse) Apply ¶
func (r *URLRedirectResponse) Apply(c context.Context, w http.ResponseWriter) error
Apply response
func (*URLRedirectResponse) Permanent ¶
func (r *URLRedirectResponse) Permanent() *URLRedirectResponse
Permanent marks a redirect as being permanent (http 301)