Documentation ¶
Overview ¶
Copyright 2012 The Gorilla Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- func Bytes2str(b []byte) string
- func Clear(r Request)
- func Delete(r Request, key interface{})
- func Get(r Request, key interface{}) interface{}
- func GetAll(r Request) map[interface{}]interface{}
- func GetAllOk(r Request) (map[interface{}]interface{}, bool)
- func GetOk(r Request, key interface{}) (interface{}, bool)
- func Purge(maxAge int) int
- func Set(r Request, key, val interface{})
- func Str2bytes(s string) []byte
- type Config
- type Engine
- type Handler
- type HandlerFunc
- type Header
- type Request
- type Response
- type URL
- type URLValuer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clear ¶
func Clear(r Request)
Clear removes all values stored for a given request.
This is usually called by a handler wrapper to clean up request variables at the end of a request lifetime. See ClearHandler().
func Delete ¶
func Delete(r Request, key interface{})
Delete removes a value stored for a given key in a given request.
func Get ¶
func Get(r Request, key interface{}) interface{}
Get returns a value stored for a given key in a given request.
func GetAll ¶
func GetAll(r Request) map[interface{}]interface{}
GetAll returns all stored values for the request as a map. Nil is returned for invalid requests.
func GetAllOk ¶
GetAllOk returns all stored values for the request as a map and a boolean value that indicates if the request was registered.
func Purge ¶
Purge removes request data stored for longer than maxAge, in seconds. It returns the amount of requests removed.
If maxAge <= 0, all request data is removed.
This is only used for sanity check: in case context cleaning was not properly set some request data can be kept forever, consuming an increasing amount of memory. In case this is detected, Purge() must be called periodically until the problem is fixed.
Types ¶
type Config ¶
type Config struct { Address string // TCP address to listen on. Listener net.Listener // Custom `net.Listener`. If set, server accepts connections on it. TLSConfig *tls.Config TLSCertFile string // TLS certificate file path. TLSKeyFile string // TLS key file path. DisableHTTP2 bool // Disables HTTP/2. ReadTimeout time.Duration // Maximum duration before timing out read of the request. WriteTimeout time.Duration // Maximum duration before timing out write of the response. MaxConnsPerIP int MaxRequestsPerConn int MaxRequestBodySize int }
Config defines engine configuration.
type Handler ¶
Handler defines an interface to server HTTP requests via `ServeHTTP(Request, Response)` function.
func ClearHandler ¶
ClearHandler wraps an http.Handler and clears request values at the end of a request lifetime.
type HandlerFunc ¶
HandlerFunc is an adapter to allow the use of `func(Request, Response)` as HTTP handlers.
func (HandlerFunc) ServeHTTP ¶
func (h HandlerFunc) ServeHTTP(req Request, res Response)
ServeHTTP serves HTTP request.
type Header ¶
type Header interface { // Add adds the key, value pair to the header. It appends to any existing values // associated with key. Add(string, string) // Del deletes the values associated with key. Del(string) // Get gets the first value associated with the given key. If there are // no values associated with the key, Get returns "". Get(string) string // Set sets the header entries associated with key to the single element value. // It replaces any existing values associated with key. Set(string, string) Object() interface{} Std() http.Header }
Header defines an interface for HTTP header.
type Request ¶
type Request interface { // Scheme returns the HTTP protocol scheme, `http` or `https`. Scheme() string // Host returns HTTP request host. Per RFC 2616, this is either the value of // the `Host` header or the host name given in the URL itself. Host() string // SetHost sets the host of the request. SetHost(string) // URI returns the unmodified `Request-URI` sent by the client. URI() string // SetURI sets the URI of the request. SetURI(string) // URL returns `engine.URL`. URL() URL // Header returns `engine.Header`. Header() Header // Proto returns the HTTP proto. (HTTP/1.1 etc.) Proto() string // RemoteAddress returns the client's network address. RemoteAddress() string // RealIP returns the client's network address based on `X-Forwarded-For` // or `X-Real-IP` request header. RealIP() string // Method returns the request's HTTP function. Method() string // SetMethod sets the HTTP method of the request. SetMethod(string) // Body returns request's body. Body() io.ReadCloser SetBody(io.Reader) // FormValue returns the form field value for the provided name. FormValue(string) string Object() interface{} Form() URLValuer PostForm() URLValuer // MultipartForm returns the multipart form. MultipartForm() *multipart.Form // IsTLS returns true if HTTP connection is TLS otherwise false. IsTLS() bool Cookie(string) string Referer() string // UserAgent returns the client's `User-Agent`. UserAgent() string // FormFile returns the multipart form file for the provided name. FormFile(string) (multipart.File, *multipart.FileHeader, error) // ContentLength returns the size of request's body. Size() int64 BasicAuth() (string, string, bool) StdRequest() *http.Request }
Request defines an interface for HTTP request.
type Response ¶
type Response interface { // Header returns `engine.Header` Header() Header // WriteHeader sends an HTTP response header with status code. WriteHeader(int) // Write writes the data to the connection as part of an HTTP reply. Write(b []byte) (int, error) // Status returns the HTTP response status. Status() int // Size returns the number of bytes written to HTTP response. Size() int64 // Committed returns true if HTTP response header is written, otherwise false. Committed() bool // SetWriter sets the HTTP response writer. SetWriter(io.Writer) // Write returns the HTTP response writer. Writer() io.Writer Object() interface{} Hijack(func(net.Conn)) Body() []byte Redirect(string, int) NotFound() SetCookie(*http.Cookie) ServeFile(string) Error(string, ...int) StdResponseWriter() http.ResponseWriter }
Response defines an interface for HTTP response.