Documentation
¶
Overview ¶
Package controller provides a controller / action based http.Handler for the router. A Controller can have different renderer and is easy to extend. Data, Redirects and Errors can be set directly in the controller. A Context with some helpers for the response and request is provided.
Index ¶
- Constants
- Variables
- type Base
- func (c *Base) Action() string
- func (c *Base) CallAction(name string) (func(), error)
- func (c *Base) CheckBrowserCancellation() bool
- func (c *Base) Context() *context.Context
- func (c *Base) Error(code int, err error)
- func (c *Base) HasError() bool
- func (c *Base) Initialize(caller Interface)
- func (c *Base) Name() string
- func (c *Base) Redirect(status int, url string)
- func (c *Base) RenderType() string
- func (c *Base) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Base) Set(key string, value interface{})
- func (c *Base) SetContext(ctx *context.Context)
- func (c *Base) SetRenderType(s string)
- func (c *Base) T(name string, template ...map[string]interface{}) string
- func (c *Base) TP(name string, count int, template ...map[string]interface{}) string
- type Interface
Constants ¶
const ( MSG = "msg" ERROR = "error" )
const (
RenderJSON = "json"
)
predefined render types
Variables ¶
var (
ErrAction = "controller: action %v does not exist in %v"
)
Error messages
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base struct
func (*Base) CallAction ¶
CallAction will call a controller function by name. Error will return if the controller method does not exist.
func (*Base) CheckBrowserCancellation ¶
CheckBrowserCancellation checking if the browser canceled the request
func (*Base) Error ¶
Error calls the renderer Error function with the given error. As fallback a normal http.Error will be triggered.
func (*Base) HasError ¶
HasError will be true if the function Error was called. If set, the Render function will not be called.
func (*Base) Initialize ¶
Initialize the controller. Its required to set the correct reference.
func (*Base) Redirect ¶
Redirect sets a HTTP location header and status code. On a redirect the old controller data will be lost. TODO check if this should be changed and the controller data copied?
func (*Base) RenderType ¶
RenderType of the controller. Default json.
func (*Base) ServeHTTP ¶
func (c *Base) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handler.
func (*Base) SetContext ¶
SetContext to the controller.
func (*Base) SetRenderType ¶
SetRenderType of the controller.
type Interface ¶
type Interface interface { Initialize(caller Interface) // needed to set the caller reference. ServeHTTP(http.ResponseWriter, *http.Request) // Context Context() *context.Context SetContext(ctx *context.Context) // render type RenderType() string SetRenderType(string) // controller helpers Name() string Action() string Set(key string, value interface{}) Error(status int, err error) Redirect(status int, url string) // Translation T(string, ...map[string]interface{}) string TP(string, int, ...map[string]interface{}) string // helpers CheckBrowserCancellation() bool CallAction(action string) (func(), error) HasError() bool // returns true if Error(int,err) was called. }
Interface of the controller.