Documentation
¶
Index ¶
- type Context
- func (c *Context) Bind(obj interface{}) error
- func (c *Context) File(filepath string)
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) HTML(code int, html string) error
- func (c *Context) HeaderWritten() bool
- func (c *Context) JSON(code int, obj interface{}) error
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Next()
- func (c *Context) Param(key string) string
- func (c *Context) RenderHTML(code int, name string, data interface{}) error
- func (c *Context) Reset(w http.ResponseWriter, r *http.Request)
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func (c *Context) Set(key string, value interface{})
- func (c *Context) Status(code int) *Context
- func (c *Context) String(code int, format string, values ...interface{}) error
- func (c *Context) Upgrade() (*websocket.Conn, error)
- type HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
Writer http.ResponseWriter
Request *http.Request
// Handlers is the middleware chain for this request
Handlers []HandlerFunc
// Params are the route parameters
Params router.Params
// Keys is a key/value pair exclusively for the context of each request.
Keys map[string]interface{}
// Templates holds the parsed templates (injected by Engine)
Templates *template.Template
// contains filtered or unexported fields
}
Context is the context for the current request. It wraps http.ResponseWriter and *http.Request and adds helper methods.
func (*Context) Bind ¶ added in v0.1.3
Bind decodes the request body into obj and validates it. Currently supports JSON.
func (*Context) File ¶ added in v0.1.3
File writes the specified file into the body stream in an efficient way.
func (*Context) FormFile ¶ added in v0.1.3
func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
FormFile returns the first file for the provided form key.
func (*Context) Get ¶ added in v0.1.3
Get returns the value for the given key, ie: (value, true). If the value does not exist it returns (nil, false)
func (*Context) HeaderWritten ¶ added in v1.0.0
HeaderWritten reports whether the response headers have been sent. Used by middleware (e.g. Recovery) to avoid writing after response started.
func (*Context) MustGet ¶ added in v0.1.3
MustGet returns the value for the given key if it exists, otherwise it panics.
func (*Context) Next ¶
func (c *Context) Next()
Next executes the next middleware in the chain. If a handler returns an error and no response has been written yet, a 500 Internal Server Error is sent and the chain is stopped.
func (*Context) RenderHTML ¶ added in v0.1.3
RenderHTML renders the template with data and sets values content-type to "text/html".
func (*Context) Reset ¶
func (c *Context) Reset(w http.ResponseWriter, r *http.Request)
Reset re-initializes the context for a new request. Crucial for sync.Pool reuse.
func (*Context) SaveUploadedFile ¶ added in v0.1.3
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
SaveUploadedFile uploads the form file to specific dst.
func (*Context) Set ¶ added in v0.1.3
Set is used to store a new key/value pair exclusively for this context. It also lazily initializes c.Keys if it was not used previously.
type HandlerFunc ¶
HandlerFunc matches the KVolt handler signature.