Documentation
¶
Overview ¶
Package context provides a request and response struct which can be used in the controller. Request provides a lot of helper function and the Response offers a simple data store and different render options.
Package context todos: TODO parse files, localizer TODO body/file size limit
Index ¶
- Variables
- func RegisterRenderer(name string, renderer providerFn) error
- func RenderTypes() (map[string]Renderer, error)
- type Context
- type Renderer
- type Request
- func (r *Request) Body() []byte
- func (r *Request) Domain() string
- func (r *Request) File(k string) ([]*multipart.FileHeader, error)
- func (r *Request) Files() (map[string][]*multipart.FileHeader, error)
- func (r *Request) FullURL() string
- func (r *Request) HTTPRequest() *http.Request
- func (r *Request) Host() string
- func (r *Request) IP() string
- func (r *Request) Is(m string) bool
- func (r *Request) IsDelete() bool
- func (r *Request) IsGet() bool
- func (r *Request) IsPatch() bool
- func (r *Request) IsPost() bool
- func (r *Request) IsPut() bool
- func (r *Request) IsSecure() bool
- func (r *Request) JWTClaim() interface{}
- func (r *Request) Locale() translation.Locale
- func (r *Request) Method() string
- func (r *Request) Param(k string) ([]string, error)
- func (r *Request) Params() (map[string][]string, error)
- func (r *Request) Pattern() string
- func (r *Request) Port() int
- func (r *Request) Protocol() string
- func (r *Request) Proxy() []string
- func (r *Request) Referer() string
- func (r *Request) Scheme() string
- func (r *Request) SetBody(body []byte)
- func (r *Request) Site() string
- func (r *Request) URI() string
- func (r *Request) URL() string
- type Response
- func (w *Response) Error(code int, err error, renderType string) error
- func (w *Response) Render(renderType string) error
- func (w *Response) ResetValues()
- func (w *Response) SetValue(key string, value interface{})
- func (w *Response) Value(key string) interface{}
- func (w *Response) Values() map[string]interface{}
- func (w *Response) Writer() http.ResponseWriter
Constants ¶
This section is empty.
Variables ¶
var (
DefaultLang string
)
Localizer of the request. Its added by the server.Translation. The controller can not call the server package (import cycle), thats why its here.
var (
ErrParam = "context: the param %#v does not exist"
)
Error messages.
Functions ¶
func RegisterRenderer ¶
RegisterRenderer provider.
func RenderTypes ¶
RenderTypes returns all registered render providers. Error will return if a renderer constructor returns one.
Types ¶
type Renderer ¶
type Renderer interface { Name() string Icon() string Write(response *Response) error Error(response *Response, code int, err error) error }
Renderer interface for the render providers.
func RenderType ¶
RenderType return a registered render provider by name. Error will return if it does not exist or the renderer constructor returns one.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request struct.
func (*Request) Domain ¶
Domain is an alias of Host method.
Example: https://example.com:8080/user?id=12#test example.com
func (*Request) File ¶
func (r *Request) File(k string) ([]*multipart.FileHeader, error)
File returns the file by key. It returns a []*FileHeader because the underlying input field could be an array. Error will return on parse error or if the key does not exist.
func (*Request) Files ¶
func (r *Request) Files() (map[string][]*multipart.FileHeader, error)
Files returns all existing files. It returns a map[string][]*FileHeader because the underlying input field could be an array. Error will return on parse error.
func (*Request) FullURL ¶
FullURL returns the schema,host,port,uri
Example: https://example.com:8080/user?id=12#test https://example.com:8080/user?id=12#test
func (*Request) HTTPRequest ¶
HTTPRequest returns the original *http.Request.
func (*Request) Host ¶
Host returns the host name. Port number will be removed if existing. If no host info is available, localhost will return.
Example: https://example.com:8080/user?id=12#test example.com
func (*Request) JWTClaim ¶
func (r *Request) JWTClaim() interface{}
JWTClaim is a helper to return the claim. The claim will be checked by the request context with the key "JWT". Nil will return if it was not set.
func (*Request) Locale ¶
func (r *Request) Locale() translation.Locale
Locale is used to translate message ids in the controller.
func (*Request) Param ¶
Param returns a parameter by key. It returns a []string because the underlying HTML input field could be an array. Error will return on parse error or if the key does not exist.
func (*Request) Params ¶
Params returns all existing parameters. It returns a map[string][]string because the underlying HTML input field could be an array. Error will return on parse error.
func (*Request) Pattern ¶
Pattern returns the router url pattern. The pattern will be checked by the request context with the key "router_pattern". If the pattern is not set, an empty string will return.
Example: http://example.com/user/1 /user/:id
func (*Request) Scheme ¶
Scheme (http/https) checks the `X-Forwarded-Proto` header. If that one is empty the URL.Scheme gets checked. If that is also empty the request TLS will be checked.
func (*Request) Site ¶
Site returns base site url as scheme://domain type without the port.
Example: https://example.com:8080/user?id=12#test https://example.com
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response struct.
func (*Response) Error ¶
Error will render the error message by the given render type. An error will return if the render provider does not exist or the renders error function returns one.
func (*Response) Render ¶
Render will render the content by the given render type. An error will return if the render provider does not exist or the renders write function returns one.
func (*Response) ResetValues ¶
func (w *Response) ResetValues()
ResetValues will create a new data instance.
func (*Response) Writer ¶
func (w *Response) Writer() http.ResponseWriter
Writer returns the *http.ResponseWriter.