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 render function.
Index ¶
- Variables
- func Providers() map[string]provider
- func Register(provider string, fn provider) error
- type Context
- type Interface
- type Request
- func (req *Request) Body() []byte
- func (req *Request) Domain() string
- func (req *Request) File(k string) ([]*multipart.FileHeader, error)
- func (req *Request) Files() (map[string][]*multipart.FileHeader, error)
- func (req *Request) FullURL() string
- func (req *Request) Host() string
- func (req *Request) IP() string
- func (req *Request) Is(m string) bool
- func (req *Request) IsDelete() bool
- func (req *Request) IsGet() bool
- func (req *Request) IsPatch() bool
- func (req *Request) IsPost() bool
- func (req *Request) IsPut() bool
- func (req *Request) IsSecure() bool
- func (req *Request) Localizer() locale.LocalizerI
- func (req *Request) Method() string
- func (req *Request) Param(k string) ([]string, error)
- func (req *Request) Params() (map[string][]string, error)
- func (req *Request) Pattern() string
- func (req *Request) Port() int
- func (req *Request) Protocol() string
- func (req *Request) Proxy() []string
- func (req *Request) Raw() *http.Request
- func (req *Request) Referer() string
- func (req *Request) Scheme() string
- func (req *Request) SetBody(body []byte)
- func (req *Request) Site() string
- func (req *Request) Token() interface{}
- func (req *Request) URI() string
- func (req *Request) URL() string
- func (req *Request) UserAgent() *UserAgent
- type Response
- type UserAgent
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownProvider = "cache: unknown response-provider %q" ErrNoProvider = errors.New("cache: empty cache-name or cache-provider is nil") ErrProviderAlreadyExists = "cache: cache-provider %#v is already registered" )
Error messages
var ErrParameter = errors.New("controller/request: the parameter %#v does not exist")
ErrParameter error message
Functions ¶
Types ¶
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 (req *Request) File(k string) ([]*multipart.FileHeader, error)
File returns the requested file of a multipart POST. 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 (req *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) 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) IP ¶
IP of the request. First it checks the proxy X-Forwarded-For Header and takes the first entry - if exists. Otherwise the RemoteAddr will be returned without the Port. TODO Header RemoteAddr (is it official?) or X-Real-Ip
func (*Request) Is ¶
Is checks the given method with the request HTTP Method. Both strings are getting set to uppercase.
func (*Request) Localizer ¶
func (req *Request) Localizer() locale.LocalizerI
func (*Request) Param ¶
Param returns the requested parameter. 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 must be defined in the request context by the key router.PATTERN. This is usually done by the router.
Example: http://example.com/user/1 /user/:id
func (*Request) Port ¶
Port returns request client port. On error or if its empty the standard port 80 will return.
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
func (*Request) Token ¶
func (req *Request) Token() interface{}
Token returns the jwt token TODO check if needed?
func (*Request) URI ¶
URI returns full request url with query string, fragment.
Example: https://example.com:8080/user?id=12#test /user?id=12#test
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response struct.
func (*Response) Raw ¶
func (o *Response) Raw() http.ResponseWriter
Raw returns the original *http.ResponseWriter