Documentation ¶
Index ¶
- Constants
- Variables
- func Context_(ctx context.Context, session *Request) context.Context
- func NoCache(c context.Context, rw http.ResponseWriter)
- func URLTitle(title string) string
- type BasicResponse
- func (br *BasicResponse) Apply(c context.Context, rw http.ResponseWriter) error
- func (br *BasicResponse) GetContentLength() int
- func (br *BasicResponse) GetStatus() int
- func (br *BasicResponse) Hook(hooks ...ResponseHook) Response
- func (br *BasicResponse) OnResponse(c context.Context, r *Request, rw http.ResponseWriter)
- type ContentResponse
- type DataResponse
- type ErrorResponse
- type GetPartialDataFunc
- type HTTPResponse
- type JSONResponse
- type OnResponse
- type Redirect
- type RedirectResponse
- func (rr *RedirectResponse) Apply(c context.Context, rw http.ResponseWriter) error
- func (rr *RedirectResponse) Hook(hooks ...ResponseHook) Response
- func (rr *RedirectResponse) OnResponse(c context.Context, r *Request, rw http.ResponseWriter)
- func (rr *RedirectResponse) With(key string, data interface{}) Redirect
- type RenderResponse
- type Request
- func (r *Request) Form(n string) ([]string, bool)
- func (r *Request) Form1(n string) (string, bool)
- func (r *Request) FormAll() map[string][]string
- func (r *Request) LoadParams(p map[string]string) *Request
- func (r *Request) MustForm(n string) []string
- func (r *Request) MustForm1(n string) string
- func (r *Request) MustParam1(n string) string
- func (r *Request) MustQuery(n string) []string
- func (r *Request) MustQuery1(n string) string
- func (r *Request) Param1(n string) (string, bool)
- func (r *Request) ParamAll() map[string]string
- func (r *Request) Query(n string) ([]string, bool)
- func (r *Request) Query1(n string) (string, bool)
- func (r *Request) QueryAll() map[string][]string
- func (r *Request) RemoteAddress() []string
- func (r *Request) Request() *http.Request
- func (r *Request) Session() *Session
- func (r *Request) WithVars(vars map[string]string) *Request
- type Responder
- func (r *Responder) Data(data interface{}) *DataResponse
- func (r *Responder) Forbidden(err error) *ServerErrorResponse
- func (r *Responder) HTTP(status uint, body io.Reader) *HTTPResponse
- func (r *Responder) Inject(engine template.Engine, router ReverseRouter, 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() *HTTPResponse
- func (r *Responder) URLRedirect(url *url.URL) *URLRedirectResponse
- func (r *Responder) Unavailable(err error) *ServerErrorResponse
- type Response
- type ResponseHook
- type ReverseRouter
- type RouteRedirectResponse
- type ServeHTTPResponse
- type ServerErrorResponse
- type Session
- func (s *Session) AddFlash(value interface{}, vars ...string)
- func (s *Session) Delete(key interface{})
- func (s *Session) Flashes(vars ...string) []interface{}
- func (s *Session) G() *sessions.Session
- func (s *Session) ID() (id string)
- func (s *Session) Load(key interface{}) (data interface{}, ok bool)
- func (s *Session) Store(key interface{}, data interface{})
- func (s *Session) Try(key interface{}) (data interface{})
- type SetPartialDataFunc
- type URLRedirectResponse
- type VerboseResponseWriter
Examples ¶
Constants ¶
const ( // INFO notice INFO = "info" // WARNING notice WARNING = "warning" // ERROR notice ERROR = "error" )
todo: still necessary?
Variables ¶
var ( // ErrFormNotFound is triggered for missing form values ErrFormNotFound = errors.New("form value not found") // ErrParamNotFound for missing router params ErrParamNotFound = errors.New("param value not found") // ErrQueryNotFound for missing query params ErrQueryNotFound = errors.New("query value not found") )
Functions ¶
Types ¶
type BasicResponse ¶
type BasicResponse struct { Status int // contains filtered or unexported fields }
BasicResponse defines a response with basic attributes
func (*BasicResponse) Apply ¶
func (br *BasicResponse) Apply(c context.Context, rw http.ResponseWriter) error
Apply sets status and content size of the response
func (*BasicResponse) GetContentLength ¶
func (br *BasicResponse) GetContentLength() int
GetContentLength returns the content size of the response
func (*BasicResponse) GetStatus ¶
func (br *BasicResponse) GetStatus() int
GetStatus returns the status of the response
func (*BasicResponse) Hook ¶
func (br *BasicResponse) Hook(hooks ...ResponseHook) Response
Hook appends hooks to the response
func (*BasicResponse) OnResponse ¶
func (br *BasicResponse) OnResponse(c context.Context, r *Request, rw http.ResponseWriter)
OnResponse callback to apply hooks
type ContentResponse ¶
type ContentResponse struct { BasicResponse Body io.Reader ContentType string }
ContentResponse contains a response with body
func (*ContentResponse) Apply ¶
func (cr *ContentResponse) Apply(c context.Context, rw http.ResponseWriter) error
Apply ContentResponse
func (*ContentResponse) Hook ¶
func (cr *ContentResponse) Hook(hooks ...ResponseHook) Response
Hook appends hooks to the response
type DataResponse ¶
type DataResponse struct { HTTPResponse 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
func (*DataResponse) Hook ¶
func (r *DataResponse) Hook(hooks ...ResponseHook) Response
Hook helper deprecated: to be removed
type ErrorResponse ¶
ErrorResponse wraps a response with an error
type GetPartialDataFunc ¶
type GetPartialDataFunc struct{}
func (*GetPartialDataFunc) Func ¶
func (*GetPartialDataFunc) Func(c context.Context) interface{}
type HTTPResponse ¶
type HTTPResponse struct { Status uint Body io.Reader Header http.Header // contains filtered or unexported fields }
HTTPResponse contains a status and a body
func (*HTTPResponse) Apply ¶
func (r *HTTPResponse) Apply(c context.Context, w http.ResponseWriter) error
Apply response
func (HTTPResponse) GetContentLength ¶
func (HTTPResponse) GetContentLength() int
GetContentLength returns the bodies content length
func (*HTTPResponse) GetStatus ¶
func (r *HTTPResponse) GetStatus() int
GetStatus returns the HTTP status
func (*HTTPResponse) Hook ¶
func (r *HTTPResponse) Hook(hooks ...ResponseHook) Response
Hook helper deprecated: to be removed
type JSONResponse ¶
type JSONResponse struct { BasicResponse Data interface{} }
JSONResponse returns Data encoded as JSON todo: create a generic data response instead
func (*JSONResponse) Apply ¶
func (jr *JSONResponse) Apply(c context.Context, rw http.ResponseWriter) error
Apply JSONResponse
func (*JSONResponse) Hook ¶
func (jr *JSONResponse) Hook(hooks ...ResponseHook) Response
Hook appends hooks to the response
type OnResponse ¶
type OnResponse interface {
OnResponse(context.Context, *Request, http.ResponseWriter)
}
OnResponse hook
type RedirectResponse ¶
type RedirectResponse struct { BasicResponse Location string // contains filtered or unexported fields }
RedirectResponse redirect
func (*RedirectResponse) Apply ¶
func (rr *RedirectResponse) Apply(c context.Context, rw http.ResponseWriter) error
Apply Response
func (*RedirectResponse) Hook ¶
func (rr *RedirectResponse) Hook(hooks ...ResponseHook) Response
Hook appends hooks to the response
func (*RedirectResponse) OnResponse ¶
func (rr *RedirectResponse) OnResponse(c context.Context, r *Request, rw http.ResponseWriter)
OnResponse Hook
func (*RedirectResponse) With ¶
func (rr *RedirectResponse) With(key string, data interface{}) Redirect
With adds data to the web response
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
func (*RenderResponse) Hook ¶
func (r *RenderResponse) Hook(hooks ...ResponseHook) Response
Hook helper deprecated: to be removed
type Request ¶
Request defines a web request
func FromContext ¶
FromContext retrieves the Request from the context
func RequestFromRequest ¶
RequestFromRequest wraps a http Request
func (*Request) LoadParams ¶
LoadParams load request params
func (*Request) MustParam1 ¶
MustParam1 panics if n is not found
func (*Request) MustQuery1 ¶
MustQuery1 panics if n is not found
func (*Request) RemoteAddress ¶
RemoteAddress get the requests real remote address
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) Forbidden ¶
func (r *Responder) Forbidden(err error) *ServerErrorResponse
Forbidden creates a 403 error response
func (*Responder) HTTP ¶
func (r *Responder) HTTP(status uint, body io.Reader) *HTTPResponse
HTTP Response generator
func (*Responder) Inject ¶
func (r *Responder) Inject(engine template.Engine, router ReverseRouter, 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) TODO ¶
func (r *Responder) TODO() *HTTPResponse
TODO creates a 501 Not Implemented response
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 Response ¶
type Response interface { // Apply executes the response on the http.ResponseWriter Apply(context.Context, http.ResponseWriter) error GetStatus() int GetContentLength() int Hook(...ResponseHook) Response }
Response defines the generic web response
type ResponseHook ¶
type ResponseHook func(c context.Context, rw http.ResponseWriter)
type ReverseRouter ¶
ReverseRouter for RouteRedirect Responses
type RouteRedirectResponse ¶
type RouteRedirectResponse struct { HTTPResponse 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) Hook ¶
func (r *RouteRedirectResponse) Hook(hooks ...ResponseHook) Response
Hook helper deprecated: to be removed
type ServeHTTPResponse ¶
type ServeHTTPResponse struct { *VerboseResponseWriter BasicResponse }
ServeHTTPResponse wraps the original response with a VerboseResponseWriter
func (*ServeHTTPResponse) Apply ¶
func (shr *ServeHTTPResponse) Apply(c context.Context, rw http.ResponseWriter) error
Apply Response (empty, it has already been applied)
func (*ServeHTTPResponse) Hook ¶
func (shr *ServeHTTPResponse) Hook(hooks ...ResponseHook) Response
Hook appends hooks to the response
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
func (*ServerErrorResponse) Hook ¶
func (r *ServerErrorResponse) Hook(hooks ...ResponseHook) Response
Hook helper deprecated: to be removed
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) AddFlash ¶
AddFlash adds a flash message to the session.
A single variadic argument is accepted, and it is optional: it defines the flash key. If not defined "_flash" is used by default.
func (*Session) Delete ¶
func (s *Session) Delete(key interface{})
Delete a given key from the session
func (*Session) Flashes ¶
Flashes returns a slice of flash messages from the session.
A single variadic argument is accepted, and it is optional: it defines the flash key. If not defined "_flash" is used by default.
type SetPartialDataFunc ¶
type SetPartialDataFunc struct{}
func (*SetPartialDataFunc) Func ¶
func (*SetPartialDataFunc) Func(c context.Context) interface{}
type URLRedirectResponse ¶
type URLRedirectResponse struct { HTTPResponse URL *url.URL }
URLRedirectResponse redirects to a certain URL
func (*URLRedirectResponse) Apply ¶
func (r *URLRedirectResponse) Apply(c context.Context, w http.ResponseWriter) error
Apply response
func (*URLRedirectResponse) Hook ¶
func (r *URLRedirectResponse) Hook(hooks ...ResponseHook) Response
Hook helper deprecated: to be removed
type VerboseResponseWriter ¶
type VerboseResponseWriter struct { http.ResponseWriter Status int Size int }
VerboseResponseWriter shadows http.ResponseWriter and tracks written bytes and result Status for logging.
func (*VerboseResponseWriter) Write ¶
func (response *VerboseResponseWriter) Write(data []byte) (int, error)
Write calls http.ResponseWriter.Write and records the written bytes.
func (*VerboseResponseWriter) WriteHeader ¶
func (response *VerboseResponseWriter) WriteHeader(h int)
WriteHeader calls http.ResponseWriter.WriteHeader and records the Status code.