responder

package
v0.0.0-...-fd23dd1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2019 License: OSL-3.0 Imports: 11 Imported by: 14

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DebugError

type DebugError struct {
	Err error
}

DebugError holds additional information

func (DebugError) Error

func (de DebugError) Error() string

Error implements error interface

func (DebugError) String

func (de DebugError) String() string

Error implements error interface

type EmptyError

type EmptyError struct{}

EmptyError in case we want to hide our error

func (EmptyError) Error

func (ee EmptyError) Error() string

Error implements error interface

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

func (r *FlamingoErrorAware) Error(context context.Context, err error) web.Response

Error returns a web.ContentResponse with status 503 and ContentType text/html

func (*FlamingoErrorAware) ErrorNotFound

func (r *FlamingoErrorAware) ErrorNotFound(context context.Context, error error) web.Response

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

func (*FlamingoJSONAware) JSONError

func (r *FlamingoJSONAware) JSONError(data interface{}, statusCode int) web.Response

JSONError returns a web.ContentResponse with status given

type FlamingoRedirectAware

type FlamingoRedirectAware struct {
	Router *router.Router `inject:""`
}

FlamingoRedirectAware flamingo's redirect aware

func (*FlamingoRedirectAware) Redirect

func (r *FlamingoRedirectAware) Redirect(name string, args map[string]string) web.Redirect

Redirect returns a web.RedirectResponse with the proper URL

func (*FlamingoRedirectAware) RedirectPermanent

func (r *FlamingoRedirectAware) RedirectPermanent(name string, args map[string]string) web.Redirect

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

Directories

Path Synopsis
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL