handler

package
v0.0.0-...-1ce522b Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

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) CSRF

func (c *Context) CSRF() string

CSRF returns the current CSRF token.

func (*Context) FlashErrorMessage

func (c *Context) FlashErrorMessage() string

FlashErrorMessage returns the error flash message and remove it.

func (*Context) FlashMessage

func (c *Context) FlashMessage() string

FlashMessage returns the flash message and remove it.

func (*Context) GenerateOAuth2State

func (c *Context) GenerateOAuth2State() string

GenerateOAuth2State generate a new OAuth2 state.

func (*Context) IsAdminUser

func (c *Context) IsAdminUser() bool

IsAdminUser checks if the logged user is administrator.

func (*Context) IsAuthenticated

func (c *Context) IsAuthenticated() bool

IsAuthenticated returns a boolean if the user is authenticated.

func (*Context) LoggedUser

func (c *Context) LoggedUser() *model.User

LoggedUser returns all properties related to the logged user.

func (*Context) OAuth2State

func (c *Context) OAuth2State() string

OAuth2State returns the current OAuth2 state.

func (*Context) Route

func (c *Context) Route(name string, args ...interface{}) string

Route returns the path for the given arguments.

func (*Context) SessionID

func (c *Context) SessionID() string

SessionID returns the current session ID.

func (*Context) SetFlashErrorMessage

func (c *Context) SetFlashErrorMessage(message string)

SetFlashErrorMessage defines a new flash error message.

func (*Context) SetFlashMessage

func (c *Context) SetFlashMessage(message string)

SetFlashMessage defines a new flash message.

func (*Context) Translate

func (c *Context) Translate(message string, args ...interface{}) string

Translate translates a message in the current language.

func (*Context) UserID

func (c *Context) UserID() int64

UserID returns the UserID of the logged user.

func (*Context) UserLanguage

func (c *Context) UserLanguage() string

UserLanguage get the locale used by the current logged user.

func (*Context) UserSessionToken

func (c *Context) UserSessionToken() string

UserSessionToken returns the current user session token.

func (*Context) UserTimezone

func (c *Context) UserTimezone() string

UserTimezone returns the timezone used by the logged user.

type ControllerFunc

type ControllerFunc func(ctx *Context, request *Request, response *Response)

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.

func (*Handler) Use

func (h *Handler) Use(f ControllerFunc) http.Handler

Use is a wrapper around an HTTP 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 NewRequest

func NewRequest(r *http.Request) *Request

NewRequest returns a new Request.

func (*Request) Body

func (r *Request) Body() io.ReadCloser

Body returns the request body.

func (*Request) Cookie

func (r *Request) Cookie(name string) string

Cookie returns the cookie value.

func (*Request) File

func (r *Request) File(name string) (multipart.File, *multipart.FileHeader, error)

File returns uploaded file properties.

func (*Request) FormIntegerValue

func (r *Request) FormIntegerValue(param string) int64

FormIntegerValue returns a form value as integer.

func (*Request) FormValue

func (r *Request) FormValue(param string) string

FormValue returns a form value as integer.

func (*Request) HasQueryParam

func (r *Request) HasQueryParam(param string) bool

HasQueryParam checks if the query string contains the given parameter.

func (*Request) IntegerParam

func (r *Request) IntegerParam(param string) (int64, error)

IntegerParam returns an URL parameter as integer.

func (*Request) QueryIntegerParam

func (r *Request) QueryIntegerParam(param string, defaultValue int) int

QueryIntegerParam returns a querystring parameter as string.

func (*Request) QueryStringParam

func (r *Request) QueryStringParam(param, defaultValue string) string

QueryStringParam returns a querystring parameter as string.

func (*Request) Request

func (r *Request) Request() *http.Request

Request returns the raw Request struct.

func (*Request) StringParam

func (r *Request) StringParam(param, defaultValue string) string

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) Cache

func (r *Response) Cache(mimeType, etag string, content []byte, duration time.Duration)

Cache returns a response with caching headers.

func (*Response) HTML

func (r *Response) HTML() *HTMLResponse

HTML returns a HTMLResponse.

func (*Response) JSON

func (r *Response) JSON() *JSONResponse

JSON returns a JSONResponse.

func (*Response) NotModified

func (r *Response) NotModified()

NotModified sends a response with a 304 status code.

func (*Response) Redirect

func (r *Response) Redirect(path string)

Redirect redirects the user to another location.

func (*Response) SetCookie

func (r *Response) SetCookie(cookie *http.Cookie)

SetCookie send a cookie to the client.

func (*Response) XML

func (r *Response) XML() *XMLResponse

XML returns a XMLResponse.

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.

Jump to

Keyboard shortcuts

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