Documentation ¶
Index ¶
- type Context
- func (c *Context) CSRF() string
- func (c *Context) FlashErrorMessage() string
- func (c *Context) FlashMessage() string
- func (c *Context) GenerateOAuth2State() string
- func (c *Context) IsAdminUser() bool
- func (c *Context) IsAuthenticated() bool
- func (c *Context) LoggedUser() *model.User
- func (c *Context) OAuth2State() string
- func (c *Context) Route(name string, args ...interface{}) string
- func (c *Context) SessionID() string
- func (c *Context) SetFlashErrorMessage(message string)
- func (c *Context) SetFlashMessage(message string)
- func (c *Context) Translate(message string, args ...interface{}) string
- func (c *Context) UserID() int64
- func (c *Context) UserLanguage() string
- func (c *Context) UserSessionToken() string
- func (c *Context) UserTimezone() string
- type ControllerFunc
- type HTMLResponse
- type Handler
- type JSONResponse
- type Request
- func (r *Request) Body() io.ReadCloser
- func (r *Request) Cookie(name string) string
- func (r *Request) File(name string) (multipart.File, *multipart.FileHeader, error)
- func (r *Request) FormIntegerValue(param string) int64
- func (r *Request) FormValue(param string) string
- func (r *Request) HasQueryParam(param string) bool
- func (r *Request) IntegerParam(param string) (int64, error)
- func (r *Request) QueryIntegerParam(param string, defaultValue int) int
- func (r *Request) QueryStringParam(param, defaultValue string) string
- func (r *Request) Request() *http.Request
- func (r *Request) StringParam(param, defaultValue string) string
- type Response
- func (r *Response) Cache(mimeType, etag string, content []byte, duration time.Duration)
- func (r *Response) HTML() *HTMLResponse
- func (r *Response) JSON() *JSONResponse
- func (r *Response) NotModified()
- func (r *Response) Redirect(path string)
- func (r *Response) SetCookie(cookie *http.Cookie)
- func (r *Response) XML() *XMLResponse
- type XMLResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context contains helper functions related to the current request.
func NewContext ¶
func NewContext(r *http.Request, store *storage.Storage, router *mux.Router, translator *locale.Translator) *Context
NewContext creates a new Context.
func (*Context) FlashErrorMessage ¶
FlashErrorMessage returns the error flash message and remove it.
func (*Context) FlashMessage ¶
FlashMessage returns the flash message and remove it.
func (*Context) GenerateOAuth2State ¶
GenerateOAuth2State generate a new OAuth2 state.
func (*Context) IsAdminUser ¶
IsAdminUser checks if the logged user is administrator.
func (*Context) IsAuthenticated ¶
IsAuthenticated returns a boolean if the user is authenticated.
func (*Context) LoggedUser ¶
LoggedUser returns all properties related to the logged user.
func (*Context) OAuth2State ¶
OAuth2State returns the current OAuth2 state.
func (*Context) SetFlashErrorMessage ¶
SetFlashErrorMessage defines a new flash error message.
func (*Context) SetFlashMessage ¶
SetFlashMessage defines a new flash message.
func (*Context) UserLanguage ¶
UserLanguage get the locale used by the current logged user.
func (*Context) UserSessionToken ¶
UserSessionToken returns the current user session token.
func (*Context) UserTimezone ¶
UserTimezone returns the timezone used by the logged user.
type ControllerFunc ¶
ControllerFunc is an application HTTP handler.
type HTMLResponse ¶
type HTMLResponse struct {
// contains filtered or unexported fields
}
HTMLResponse handles HTML responses.
func (*HTMLResponse) BadRequest ¶
func (h *HTMLResponse) BadRequest(err error)
BadRequest sends a 400 error to the browser.
func (*HTMLResponse) Forbidden ¶
func (h *HTMLResponse) Forbidden()
Forbidden sends a 403 error to the browser.
func (*HTMLResponse) NotFound ¶
func (h *HTMLResponse) NotFound()
NotFound sends a 404 error to the browser.
func (*HTMLResponse) Render ¶
func (h *HTMLResponse) Render(template string, args map[string]interface{})
Render execute a template and send to the client the generated HTML.
func (*HTMLResponse) ServerError ¶
func (h *HTMLResponse) ServerError(err error)
ServerError sends a 500 error to the browser.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages HTTP handlers and middlewares.
func NewHandler ¶
func NewHandler(cfg *config.Config, store *storage.Storage, router *mux.Router, template *template.Engine, translator *locale.Translator, middleware *middleware.Chain) *Handler
NewHandler returns a new Handler.
type JSONResponse ¶
type JSONResponse struct {
// contains filtered or unexported fields
}
JSONResponse handles JSON responses.
func NewJSONResponse ¶
func NewJSONResponse(w http.ResponseWriter, r *http.Request) *JSONResponse
NewJSONResponse returns a new JSONResponse.
func (*JSONResponse) BadRequest ¶
func (j *JSONResponse) BadRequest(err error)
BadRequest sends a JSON response with the status code 400.
func (*JSONResponse) Created ¶
func (j *JSONResponse) Created(v interface{})
Created sends a JSON response with the status code 201.
func (*JSONResponse) Forbidden ¶
func (j *JSONResponse) Forbidden()
Forbidden sends a JSON response with the status code 403.
func (*JSONResponse) NoContent ¶
func (j *JSONResponse) NoContent()
NoContent sends a JSON response with the status code 204.
func (*JSONResponse) NotFound ¶
func (j *JSONResponse) NotFound(err error)
NotFound sends a JSON response with the status code 404.
func (*JSONResponse) ServerError ¶
func (j *JSONResponse) ServerError(err error)
ServerError sends a JSON response with the status code 500.
func (*JSONResponse) Standard ¶
func (j *JSONResponse) Standard(v interface{})
Standard sends a JSON response with the status code 200.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is a thin wrapper around "http.Request".
func (*Request) FormIntegerValue ¶
FormIntegerValue returns a form value as integer.
func (*Request) HasQueryParam ¶
HasQueryParam checks if the query string contains the given parameter.
func (*Request) IntegerParam ¶
IntegerParam returns an URL parameter as integer.
func (*Request) QueryIntegerParam ¶
QueryIntegerParam returns a querystring parameter as string.
func (*Request) QueryStringParam ¶
QueryStringParam returns a querystring parameter as string.
func (*Request) StringParam ¶
StringParam returns an URL parameter as string.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response handles HTTP responses.
func NewResponse ¶
func NewResponse(cfg *config.Config, w http.ResponseWriter, r *http.Request, template *template.Engine) *Response
NewResponse returns a new Response.
func (*Response) NotModified ¶
func (r *Response) NotModified()
NotModified sends a response with a 304 status code.
type XMLResponse ¶
type XMLResponse struct {
// contains filtered or unexported fields
}
XMLResponse handles XML responses.
func (*XMLResponse) Download ¶
func (x *XMLResponse) Download(filename, data string)
Download force the download of a XML document.
func (*XMLResponse) Serve ¶
func (x *XMLResponse) Serve(data string)
Serve forces the XML to be sent to browser.