Documentation
¶
Index ¶
- Variables
- type Context
- func (c *Context) Commit() error
- func (c *Context) GetData(key interface{}) interface{}
- func (c *Context) HTML()
- func (c *Context) Init()
- func (c *Context) JSON()
- func (c *Context) Redirect(url string, code int)
- func (c *Context) Request() *http.Request
- func (c *Context) Response() http.ResponseWriter
- func (c *Context) Set(value interface{})
- func (c *Context) SetData(key, value interface{})
- func (c *Context) SetHeader(key, value string)
- func (c *Context) TextPlain()
- func (c *Context) Write(data []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
var Content = struct { Type string TextPlain string TextHTML string Application struct { Form, JSON, MultipartForm string } }{ "Content-Type", "text/plain", "text/html", struct { Form, JSON, MultipartForm string }{ "application/x-www-form-urlencoded", "application/json", "multipart/form-data", }, }
Content holds http response content type strings
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// Params are the parameters specified in the url patterns
// utron uses gorilla mux for routing. So basically Params stores results
// after calling mux.Vars function .
//
// e.g. if you have route /hello/{world}
// when you make request to /hello/gernest , then
// in the Params, key named world will have value gernest. meaning Params["world"]=="gernest"
Params map[string]string
// Data keeps values that are going to be passed to the view as context
Data map[string]interface{}
// Template is the name of the template to be rendered by the view
Template string
// Cfg is the application configuration
Cfg *config.Config
//DB is the database stuff, with all models registered
DB *models.Model
View view.View
// contains filtered or unexported fields
}
Context wraps request and response. It provides methods for handling responses
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) *Context
NewContext creates new context for the given w and r
func (*Context) Commit ¶
Commit writes the results on the underlying http.ResponseWriter and commits the changes. This should be called only once, subsequent calls to this will result in an error.
If there is a view, and the template is specified the the view is rendered and its output is written to the response, otherwise any data written to the context is written to the ResponseWriter.
func (*Context) GetData ¶
func (c *Context) GetData(key interface{}) interface{}
GetData retrievess any data stored in the request using gorilla.Context package
func (*Context) Response ¶
func (c *Context) Response() http.ResponseWriter
Response returns the http.ResponseWriter object used by the context
func (*Context) Set ¶
func (c *Context) Set(value interface{})
Set sets value in the context object. You can use this to change the following
- Request by passing *http.Request
- ResponseWriter by passing http.ResponseVritter
- view by passing View
- response status code by passing an int
func (*Context) SetData ¶
func (c *Context) SetData(key, value interface{})
SetData stores key value into the request object attached with the context. this is a helper method, wraping gorilla/context