Documentation
¶
Overview ¶
Package context provide the context utils Usage:
import "github.com/cooleo/goweb/context"
ctx := context.Context{Request:req,ResponseWriter:rw}
more docs http://goweb.me/docs/module/context.md
Index ¶
- func NewInput() *gowebInput
- func NewOutput() *gowebOutput
- func ParseEncoding(r *http.Request) string
- func WriteBody(encoding string, writer io.Writer, content []byte) (bool, string, error)
- func WriteFile(encoding string, writer io.Writer, file *os.File) (bool, string, error)
- type Context
- func (ctx *Context) Abort(status int, body string)
- func (ctx *Context) CheckXSRFCookie() bool
- func (ctx *Context) GetCookie(key string) string
- func (ctx *Context) GetSecureCookie(Secret, key string) (string, bool)
- func (ctx *Context) Redirect(status int, localurl string)
- func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)
- func (ctx *Context) SetCookie(name string, value string, others ...interface{})
- func (ctx *Context) SetSecureCookie(Secret, name, value string, others ...interface{})
- func (ctx *Context) WriteString(content string)
- func (ctx *Context) XSRFToken(key string, expire int64) string
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewOutput ¶
func NewOutput() *gowebOutput
NewOutput returns new gowebOutput. it contains nothing now.
func ParseEncoding ¶
ParseEncoding will extract the right encoding for response the Accept-Encoding's sec is here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
Types ¶
type Context ¶
type Context struct {
Input *gowebInput
Output *gowebOutput
Request *http.Request
ResponseWriter *Response
// contains filtered or unexported fields
}
Context Http request context struct including gowebInput, gowebOutput, http.Request and http.ResponseWriter. gowebInput and gowebOutput provides some api to operate request and response more easily.
func (*Context) CheckXSRFCookie ¶
CheckXSRFCookie checks xsrf token in this request is valid or not. the token can provided in request header "X-Xsrftoken" and "X-CsrfToken" or in form field value named as "_xsrf".
func (*Context) GetCookie ¶
GetCookie Get cookie from request by a given key. It's alias of gowebInput.Cookie.
func (*Context) GetSecureCookie ¶
GetSecureCookie Get secure cookie from request by a given key.
func (*Context) Redirect ¶
Redirect does redirection to localurl with http header status code. It sends http response header directly.
func (*Context) Reset ¶
func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)
Reset init Context, gowebInput and gowebOutput
func (*Context) SetSecureCookie ¶
SetSecureCookie Set Secure cookie for response.
func (*Context) WriteString ¶
WriteString Write string to response body. it sends response body.
type Response ¶
type Response struct {
http.ResponseWriter
Started bool
Status int
}
Response is a wrapper for the http.ResponseWriter started set to true if response was written to then don't execute other handler
func (*Response) CloseNotify ¶
CloseNotify http.CloseNotifier
func (*Response) Copy ¶
Copy writes the data to the connection as part of an HTTP reply, and sets `started` to true. started means the response has sent out.
func (*Response) Write ¶
Write writes the data to the connection as part of an HTTP reply, and sets `started` to true. started means the response has sent out.
func (*Response) WriteHeader ¶
WriteHeader sends an HTTP response header with status code, and sets `started` to true.