Documentation ¶
Overview ¶
Package web provides a web.go compitable layer for reusing the code written with hoisie's `web.go` framework. Basiclly this package add web.Context to martini's dependency injection system.
Index ¶
- func ContextWithCookieSecret(secret string) martini.Handler
- func NewCookie(name string, value string, age int64) *http.Cookie
- type Context
- func (ctx *Context) Abort(status int, body string)
- func (ctx *Context) ContentType(val string) string
- func (ctx *Context) Forbidden()
- func (ctx *Context) GetSecureCookie(name string) (string, bool)
- func (ctx *Context) NotFound(message string)
- func (ctx *Context) NotModified()
- func (ctx *Context) Redirect(status int, url_ string)
- func (ctx *Context) SetCookie(cookie *http.Cookie)
- func (ctx *Context) SetHeader(hdr string, val string, unique bool)
- func (ctx *Context) SetSecureCookie(name string, val string, age int64)
- func (ctx *Context) Unauthorized()
- func (ctx *Context) WriteString(content string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithCookieSecret ¶
if cookie secret is set to "", then SetSecureCookie would not work
Types ¶
type Context ¶
type Context struct { Request *http.Request Params map[string]string http.ResponseWriter // contains filtered or unexported fields }
A Context object is created for every incoming HTTP request, and is passed to handlers as an optional first argument. It provides information about the request, including the http.Request object, the GET and POST params, and acts as a Writer for the response.
func (*Context) Abort ¶
Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.
func (*Context) ContentType ¶
ContentType sets the Content-Type header for an HTTP response. For example, ctx.ContentType("json") sets the content-type to "application/json" If the supplied value contains a slash (/) it is set as the Content-Type verbatim. The return value is the content type as it was set, or an empty string if none was found.
func (*Context) NotModified ¶
func (ctx *Context) NotModified()
Notmodified writes a 304 HTTP response
func (*Context) SetHeader ¶
SetHeader sets a response header. If `unique` is true, the current value of that header will be overwritten . If false, it will be appended.
func (*Context) SetSecureCookie ¶
func (*Context) Unauthorized ¶
func (ctx *Context) Unauthorized()
Unauthorized writes a 401 HTTP response
func (*Context) WriteString ¶
WriteString writes string data into the response object.