Documentation ¶
Overview ¶
Usage:
import "github.com/astaxie/beego/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
Index ¶
- type BeegoInput
- func (input *BeegoInput) Bind(dest interface{}, key string) error
- func (input *BeegoInput) Cookie(key string) string
- func (input *BeegoInput) CopyBody() []byte
- func (input *BeegoInput) Domain() string
- func (input *BeegoInput) GetData(key interface{}) interface{}
- func (input *BeegoInput) Header(key string) string
- func (input *BeegoInput) Host() string
- func (input *BeegoInput) IP() string
- func (input *BeegoInput) Is(method string) bool
- func (input *BeegoInput) IsAjax() bool
- func (input *BeegoInput) IsDelete() bool
- func (input *BeegoInput) IsGet() bool
- func (input *BeegoInput) IsHead() bool
- func (input *BeegoInput) IsOptions() bool
- func (input *BeegoInput) IsPatch() bool
- func (input *BeegoInput) IsPost() bool
- func (input *BeegoInput) IsPut() bool
- func (input *BeegoInput) IsSecure() bool
- func (input *BeegoInput) IsUpload() bool
- func (input *BeegoInput) IsWebsocket() bool
- func (input *BeegoInput) Method() string
- func (input *BeegoInput) Param(key string) string
- func (input *BeegoInput) ParseFormOrMulitForm(maxMemory int64) error
- func (input *BeegoInput) Port() int
- func (input *BeegoInput) Protocol() string
- func (input *BeegoInput) Proxy() []string
- func (input *BeegoInput) Query(key string) string
- func (input *BeegoInput) Refer() string
- func (input *BeegoInput) Scheme() string
- func (input *BeegoInput) Session(key interface{}) interface{}
- func (input *BeegoInput) SetData(key, val interface{})
- func (input *BeegoInput) Site() string
- func (input *BeegoInput) SubDomains() string
- func (input *BeegoInput) Uri() string
- func (input *BeegoInput) Url() string
- func (input *BeegoInput) UserAgent() string
- type BeegoOutput
- func (output *BeegoOutput) Body(content []byte)
- func (output *BeegoOutput) ContentType(ext string)
- func (output *BeegoOutput) Cookie(name string, value string, others ...interface{})
- func (output *BeegoOutput) Download(file string, filename ...string)
- func (output *BeegoOutput) Header(key, val string)
- func (output *BeegoOutput) IsCachable(status int) bool
- func (output *BeegoOutput) IsClientError(status int) bool
- func (output *BeegoOutput) IsEmpty(status int) bool
- func (output *BeegoOutput) IsForbidden(status int) bool
- func (output *BeegoOutput) IsNotFound(status int) bool
- func (output *BeegoOutput) IsOk(status int) bool
- func (output *BeegoOutput) IsRedirect(status int) bool
- func (output *BeegoOutput) IsServerError(status int) bool
- func (output *BeegoOutput) IsSuccessful(status int) bool
- func (output *BeegoOutput) Json(data interface{}, hasIndent bool, coding bool) error
- func (output *BeegoOutput) Jsonp(data interface{}, hasIndent bool) error
- func (output *BeegoOutput) Session(name interface{}, value interface{})
- func (output *BeegoOutput) SetStatus(status int)
- func (output *BeegoOutput) Xml(data interface{}, hasIndent bool) 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) 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BeegoInput ¶
type BeegoInput struct { CruSession session.SessionStore Params map[string]string Data map[interface{}]interface{} // store some values in this context when calling context in filter or controller. Request *http.Request RequestBody []byte RunController reflect.Type RunMethod string }
BeegoInput operates the http request header ,data ,cookie and body. it also contains router params and current session.
func NewInput ¶
func NewInput(req *http.Request) *BeegoInput
NewInput return BeegoInput generated by http.Request.
func (*BeegoInput) Bind ¶
func (input *BeegoInput) Bind(dest interface{}, key string) error
Bind data from request.Form[key] to dest like /?id=123&isok=true&ft=1.2&ol[0]=1&ol[1]=2&ul[]=str&ul[]=array&user.Name=astaxie var id int beegoInput.Bind(&id, "id") id ==123 var isok bool beegoInput.Bind(&isok, "isok") id ==true var ft float64 beegoInput.Bind(&ft, "ft") ft ==1.2 ol := make([]int, 0, 2) beegoInput.Bind(&ol, "ol") ol ==[1 2] ul := make([]string, 0, 2) beegoInput.Bind(&ul, "ul") ul ==[str array] user struct{Name} beegoInput.Bind(&user, "user") user == {Name:"astaxie"}
func (*BeegoInput) Cookie ¶
func (input *BeegoInput) Cookie(key string) string
Cookie returns request cookie item string by a given key. if non-existed, return empty string.
func (*BeegoInput) CopyBody ¶
func (input *BeegoInput) CopyBody() []byte
Body returns the raw request body data as bytes.
func (*BeegoInput) Domain ¶
func (input *BeegoInput) Domain() string
Domain returns host name. Alias of Host method.
func (*BeegoInput) GetData ¶
func (input *BeegoInput) GetData(key interface{}) interface{}
GetData returns the stored data in this context.
func (*BeegoInput) Header ¶
func (input *BeegoInput) Header(key string) string
Header returns request header item string by a given string.
func (*BeegoInput) Host ¶
func (input *BeegoInput) Host() string
Host returns host name. if no host info in request, return localhost.
func (*BeegoInput) IP ¶
func (input *BeegoInput) IP() string
IP returns request client ip. if in proxy, return first proxy id. if error, return 127.0.0.1.
func (*BeegoInput) Is ¶
func (input *BeegoInput) Is(method string) bool
Is returns boolean of this request is on given method, such as Is("POST").
func (*BeegoInput) IsAjax ¶
func (input *BeegoInput) IsAjax() bool
IsAjax returns boolean of this request is generated by ajax.
func (*BeegoInput) IsDelete ¶
func (input *BeegoInput) IsDelete() bool
Is this a DELETE method request?
func (*BeegoInput) IsOptions ¶
func (input *BeegoInput) IsOptions() bool
Is this a OPTIONS method request?
func (*BeegoInput) IsPatch ¶
func (input *BeegoInput) IsPatch() bool
Is this a PATCH method request?
func (*BeegoInput) IsSecure ¶
func (input *BeegoInput) IsSecure() bool
IsSecure returns boolean of this request is in https.
func (*BeegoInput) IsUpload ¶
func (input *BeegoInput) IsUpload() bool
IsSecure returns boolean of whether file uploads in this request or not..
func (*BeegoInput) IsWebsocket ¶
func (input *BeegoInput) IsWebsocket() bool
IsSecure returns boolean of this request is in webSocket.
func (*BeegoInput) Method ¶
func (input *BeegoInput) Method() string
Method returns http request method.
func (*BeegoInput) Param ¶
func (input *BeegoInput) Param(key string) string
Param returns router param by a given key.
func (*BeegoInput) ParseFormOrMulitForm ¶
func (input *BeegoInput) ParseFormOrMulitForm(maxMemory int64) error
parseForm or parseMultiForm based on Content-type
func (*BeegoInput) Port ¶
func (input *BeegoInput) Port() int
Port returns request client port. when error or empty, return 80.
func (*BeegoInput) Protocol ¶
func (input *BeegoInput) Protocol() string
Protocol returns request protocol name, such as HTTP/1.1 .
func (*BeegoInput) Proxy ¶
func (input *BeegoInput) Proxy() []string
Proxy returns proxy client ips slice.
func (*BeegoInput) Query ¶
func (input *BeegoInput) Query(key string) string
Query returns input data item string by a given string.
func (*BeegoInput) Refer ¶
func (input *BeegoInput) Refer() string
Refer returns http referer header.
func (*BeegoInput) Scheme ¶
func (input *BeegoInput) Scheme() string
Scheme returns request scheme as "http" or "https".
func (*BeegoInput) Session ¶
func (input *BeegoInput) Session(key interface{}) interface{}
Session returns current session item value by a given key.
func (*BeegoInput) SetData ¶
func (input *BeegoInput) SetData(key, val interface{})
SetData stores data with given key in this context. This data are only available in this context.
func (*BeegoInput) Site ¶
func (input *BeegoInput) Site() string
Site returns base site url as scheme://domain type.
func (*BeegoInput) SubDomains ¶
func (input *BeegoInput) SubDomains() string
SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .
func (*BeegoInput) Uri ¶
func (input *BeegoInput) Uri() string
Uri returns full request url with query string, fragment.
func (*BeegoInput) Url ¶
func (input *BeegoInput) Url() string
Url returns request url path (without query string, fragment).
func (*BeegoInput) UserAgent ¶
func (input *BeegoInput) UserAgent() string
UserAgent returns request client user agent string.
type BeegoOutput ¶
BeegoOutput does work for sending response header.
func NewOutput ¶
func NewOutput() *BeegoOutput
NewOutput returns new BeegoOutput. it contains nothing now.
func (*BeegoOutput) Body ¶
func (output *BeegoOutput) Body(content []byte)
Body sets response body content. if EnableGzip, compress content string. it sends out response body directly.
func (*BeegoOutput) ContentType ¶
func (output *BeegoOutput) ContentType(ext string)
ContentType sets the content type from ext string. MIME type is given in mime package.
func (*BeegoOutput) Cookie ¶
func (output *BeegoOutput) Cookie(name string, value string, others ...interface{})
Cookie sets cookie value via given key. others are ordered as cookie's max age time, path,domain, secure and httponly.
func (*BeegoOutput) Download ¶
func (output *BeegoOutput) Download(file string, filename ...string)
Download forces response for download file. it prepares the download response header automatically.
func (*BeegoOutput) Header ¶
func (output *BeegoOutput) Header(key, val string)
Header sets response header item string via given key.
func (*BeegoOutput) IsCachable ¶
func (output *BeegoOutput) IsCachable(status int) bool
IsCachable returns boolean of this request is cached. HTTP 304 means cached.
func (*BeegoOutput) IsClientError ¶
func (output *BeegoOutput) IsClientError(status int) bool
IsClient returns boolean of this request client sends error data. HTTP 4xx means forbidden.
func (*BeegoOutput) IsEmpty ¶
func (output *BeegoOutput) IsEmpty(status int) bool
IsEmpty returns boolean of this request is empty. HTTP 201,204 and 304 means empty.
func (*BeegoOutput) IsForbidden ¶
func (output *BeegoOutput) IsForbidden(status int) bool
IsForbidden returns boolean of this request is forbidden. HTTP 403 means forbidden.
func (*BeegoOutput) IsNotFound ¶
func (output *BeegoOutput) IsNotFound(status int) bool
IsNotFound returns boolean of this request is not found. HTTP 404 means forbidden.
func (*BeegoOutput) IsOk ¶
func (output *BeegoOutput) IsOk(status int) bool
IsOk returns boolean of this request runs well. HTTP 200 means ok.
func (*BeegoOutput) IsRedirect ¶
func (output *BeegoOutput) IsRedirect(status int) bool
IsRedirect returns boolean of this request is redirection header. HTTP 301,302,307 means redirection.
func (*BeegoOutput) IsServerError ¶
func (output *BeegoOutput) IsServerError(status int) bool
IsServerError returns boolean of this server handler errors. HTTP 5xx means server internal error.
func (*BeegoOutput) IsSuccessful ¶
func (output *BeegoOutput) IsSuccessful(status int) bool
IsSuccessful returns boolean of this request runs successfully. HTTP 2xx means ok.
func (*BeegoOutput) Json ¶
func (output *BeegoOutput) Json(data interface{}, hasIndent bool, coding bool) error
Json writes json to response body. if coding is true, it converts utf-8 to \u0000 type.
func (*BeegoOutput) Jsonp ¶
func (output *BeegoOutput) Jsonp(data interface{}, hasIndent bool) error
Jsonp writes jsonp to response body.
func (*BeegoOutput) Session ¶
func (output *BeegoOutput) Session(name interface{}, value interface{})
Sessions sets session item value with given key.
func (*BeegoOutput) SetStatus ¶
func (output *BeegoOutput) SetStatus(status int)
SetStatus sets response status code. It writes response header directly.
func (*BeegoOutput) Xml ¶
func (output *BeegoOutput) Xml(data interface{}, hasIndent bool) error
Xml writes xml string to response body.
type Context ¶
type Context struct { Input *BeegoInput Output *BeegoOutput Request *http.Request ResponseWriter http.ResponseWriter // contains filtered or unexported fields }
Http request context struct including BeegoInput, BeegoOutput, http.Request and http.ResponseWriter. BeegoInput and BeegoOutput provides some api to operate request and response more easily.
func (*Context) Abort ¶
Abort stops this request. if middleware.ErrorMaps exists, panic body. if middleware.HTTPExceptionMaps exists, panic HTTPException struct with status and body string.
func (*Context) CheckXsrfCookie ¶ added in v1.4.1
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 ¶
Get cookie from request by a given key. It's alias of BeegoInput.Cookie.
func (*Context) 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) SetSecureCookie ¶
Set Secure cookie for response.
func (*Context) WriteString ¶
Write string to response body. it sends response body.