Documentation ¶
Overview ¶
Package responder are basically helper for generating responses.
Instead of generating responses from response-structs, you should inject these responder structs and let them take care. They can request *app.App etc as they need it.
Example
type MyController struct { *responder.RenderAware `inject:""` *responder.RedirectAware `inject:""` } func (mc *MyController) Get(ctx web.Context) web.Response { return mc.Render(ctx, "template", "additional data") } func (mc *MyController) Post(ctx web.Context) web.Response { return mc.Redirect("index") }
Index ¶
- type DebugError
- type EmptyError
- type ErrorAware
- type ErrorViewData
- type FlamingoErrorAware
- type FlamingoJSONAware
- type FlamingoRedirectAware
- func (r *FlamingoRedirectAware) Redirect(name string, args map[string]string) web.Redirect
- func (r *FlamingoRedirectAware) RedirectPermanent(name string, args map[string]string) web.Redirect
- func (r *FlamingoRedirectAware) RedirectPermanentURL(url string) web.Redirect
- func (r *FlamingoRedirectAware) RedirectURL(url string) web.Redirect
- type FlamingoRenderAware
- type JSONAware
- type RedirectAware
- type RenderAware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorAware ¶
type ErrorAware interface { Error(context context.Context, err error) web.Response ErrorNotFound(context context.Context, err error) web.Response ErrorWithCode(context context.Context, err error, httpStatus int) web.Response }
ErrorAware responder trait
type ErrorViewData ¶
type ErrorViewData struct { Code int `json:"code"` Error error `json:"error"` Errortext string `json:"errortex"` }
ErrorViewData for template rendering
type FlamingoErrorAware ¶
type FlamingoErrorAware struct { RenderAware `inject:""` DebugMode bool `inject:"config:debug.mode"` Tpl404 string `inject:"config:flamingo.template.err404"` TplErrorWithCode string `inject:"config:flamingo.template.errWithCode"` Tpl503 string `inject:"config:flamingo.template.err503"` Logger flamingo.Logger `inject:""` }
FlamingoErrorAware responder can return errors
func (*FlamingoErrorAware) Error ¶
Error returns a web.ContentResponse with status 503 and ContentType text/html
func (*FlamingoErrorAware) ErrorNotFound ¶
ErrorNotFound returns a web.ContentResponse with status 404 and ContentType text/html
func (*FlamingoErrorAware) ErrorWithCode ¶
func (r *FlamingoErrorAware) ErrorWithCode(context context.Context, error error, httpStatus int) web.Response
ErrorWithCode returns a web.ContentResponse with give status code and ContentType text/html
type FlamingoJSONAware ¶
type FlamingoJSONAware struct{}
FlamingoJSONAware allows pug_template rendering
func (*FlamingoJSONAware) JSON ¶
func (r *FlamingoJSONAware) JSON(data interface{}) web.Response
JSON returns a web.ContentResponse with status 200
type FlamingoRedirectAware ¶
FlamingoRedirectAware flamingo's redirect aware
func (*FlamingoRedirectAware) Redirect ¶
Redirect returns a web.RedirectResponse with the proper URL
func (*FlamingoRedirectAware) RedirectPermanent ¶
RedirectPermanent returns a web.RedirectPermanentResponse with the proper URL
func (*FlamingoRedirectAware) RedirectPermanentURL ¶
func (r *FlamingoRedirectAware) RedirectPermanentURL(url string) web.Redirect
RedirectPermanentURL returns a web.RedirectResponse with the proper URL
func (*FlamingoRedirectAware) RedirectURL ¶
func (r *FlamingoRedirectAware) RedirectURL(url string) web.Redirect
RedirectURL returns a web.RedirectResponse with the proper URL
type FlamingoRenderAware ¶
type FlamingoRenderAware struct { Router *router.Router `inject:""` Engine template.Engine `inject:",optional"` // contains filtered or unexported fields }
FlamingoRenderAware allows pug_template rendering
func (*FlamingoRenderAware) Render ¶
func (r *FlamingoRenderAware) Render(context context.Context, tpl string, data interface{}) (response web.Response)
Render returns a web.ContentResponse with status 200 and ContentType text/html
func (*FlamingoRenderAware) WithStatusCode ¶
func (r *FlamingoRenderAware) WithStatusCode(code int) RenderAware
WithStatusCode sets the HTTP status code for the response
type JSONAware ¶
type JSONAware interface { JSON(data interface{}) web.Response JSONError(data interface{}, statusCode int) web.Response }
JSONAware controller trait
type RedirectAware ¶
type RedirectAware interface { Redirect(name string, args map[string]string) web.Redirect RedirectURL(url string) web.Redirect RedirectPermanent(name string, args map[string]string) web.Redirect RedirectPermanentURL(url string) web.Redirect }
RedirectAware trait
type RenderAware ¶
type RenderAware interface { Render(context context.Context, tpl string, data interface{}) web.Response WithStatusCode(code int) RenderAware }
RenderAware controller trait