Package context provide the context utils Usage:
import "github.com/astaxie/beego/context" ctx := context.Context{Request:req,ResponseWriter:rw} more docs http://beego.me/docs/module/context.md
const ( ApplicationJSON = "application/json" ApplicationXML = "application/xml" ApplicationYAML = "application/x-yaml" TextXML = "text/xml" )
commonly used mime-types
This section is empty.
func InitGzip(minLength, compressLevel int, methods []string)
InitGzip init the gzipcompress
func WriteBody ¶ added in v1.6.0WriteBody reads writes content to writer by the specific encoding(gzip/deflate)
WriteFile reads from file and writes to writer by the specific encoding(gzip/deflate)
BeegoInput operates the http request header, data, cookie and body. it also contains router params and current session.
NewInput return BeegoInput generated by Context.
AcceptsHTML Checks if request accepts html response
AcceptsJSON Checks if request accepts json response
AcceptsXML Checks if request accepts xml response
AcceptsYAML Checks if request accepts json response
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") isok ==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"}
Cookie returns request cookie item string by a given key. if non-existed, return empty string.
func (*BeegoInput) CopyBody ¶CopyBody returns the raw request body data as bytes.
func (input *BeegoInput) Data() map[interface{}]interface{}
Data return the implicit data in the input
func (*BeegoInput) Domain ¶Domain returns host name. Alias of Host method.
func (input *BeegoInput) GetData(key interface{}) interface{}
GetData returns the stored data in this context.
Header returns request header item string by a given string. if non-existed, return empty string.
Host returns host name. if no host info in request, return localhost.
IP returns request client ip. if in proxy, return first proxy id. if error, return RemoteAddr.
Is returns boolean of this request is on given method, such as Is("POST").
IsAjax returns boolean of this request is generated by ajax.
IsDelete Is this a DELETE method request?
IsGet Is this a GET method request?
IsHead Is this a Head method request?
IsOptions Is this a OPTIONS method request?
IsPatch Is this a PATCH method request?
IsPost Is this a POST method request?
IsPut Is this a PUT method request?
IsSecure returns boolean of this request is in https.
IsUpload returns boolean of whether file uploads in this request or not..
IsWebsocket returns boolean of this request is in webSocket.
Method returns http request method.
Param returns router param by a given key.
Params returns the map[key]value.
ParamsLen return the length of the params
ParseFormOrMulitForm parseForm or parseMultiForm based on Content-type
Port returns request client port. when error or empty, return 80.
Protocol returns request protocol name, such as HTTP/1.1 .
Proxy returns proxy client ips slice.
Query returns input data item string by a given string.
Refer returns http referer header.
Referer returns http referer header.
Reset init the BeegoInput
ResetParams clears any of the input's Params This function is used to clear parameters so they may be reset between filter passes.
Scheme returns request scheme as "http" or "https".
func (input *BeegoInput) Session(key interface{}) interface{}
Session returns current session item value by a given key. if non-existed, return nil.
func (input *BeegoInput) SetData(key, val interface{})
SetData stores data with given key in this context. This data are only available in this context.
SetParam will set the param with key and value
Site returns base site url as scheme://domain type.
func (*BeegoInput) SubDomains ¶SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .
URI returns full request url with query string, fragment.
URL returns request url path (without query string, fragment).
UserAgent returns request client user agent string.
type BeegoOutput struct { Context *Context Status int EnableGzip bool }
BeegoOutput does work for sending response header.
NewOutput returns new BeegoOutput. it contains nothing now.
func (*BeegoOutput) Body ¶Body sets response body content. if EnableGzip, compress content string. it sends out response body directly.
ContentType sets the content type from ext string. MIME type is given in mime package.
Cookie sets cookie value via given key. others are ordered as cookie's max age time, path,domain, secure and httponly.
Download forces response for download file. it prepares the download response header automatically.
Header sets response header item string via given key.
IsCachable returns boolean of this request is cached. HTTP 304 means cached.
IsClientError returns boolean of this request client sends error data. HTTP 4xx means client error.
IsEmpty returns boolean of this request is empty. HTTP 201,204 and 304 means empty.
IsForbidden returns boolean of this request is forbidden. HTTP 403 means forbidden.
IsNotFound returns boolean of this request is not found. HTTP 404 means not found.
IsOk returns boolean of this request runs well. HTTP 200 means ok.
IsRedirect returns boolean of this request is redirection header. HTTP 301,302,307 means redirection.
IsServerError returns boolean of this server handler errors. HTTP 5xx means server internal error.
IsSuccessful returns boolean of this request runs successfully. HTTP 2xx means ok.
JSON writes json to response body. if encoding is true, it converts utf-8 to \u0000 type.
JSONP writes jsonp to response body.
ServeFormatted serve YAML, XML OR JSON, depending on the value of the Accept header
func (output *BeegoOutput) Session(name interface{}, value interface{})
Session sets session item value with given key.
SetStatus sets response status code. It writes response header directly.
XML writes xml string to response body.
YAML writes yaml to response body.
Context 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.
NewContext return the Context with Input and Output
Abort stops this request. if beego.ErrorMaps exists, panic body.
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".
GetCookie Get cookie from request by a given key. It's alias of BeegoInput.Cookie.
GetSecureCookie Get secure cookie from request by a given key.
Redirect does redirection to localurl with http header status code.
func (ctx *Context) RenderMethodResult(result interface{})
RenderMethodResult renders the return value of a controller method to the output
Reset init Context, BeegoInput and BeegoOutput
SetCookie Set cookie for response. It's alias of BeegoOutput.Cookie.
func (ctx *Context) SetSecureCookie(Secret, name, value string, others ...interface{})
SetSecureCookie Set Secure cookie for response.
WriteString Write string to response body. it sends response body.
XSRFToken creates a xsrf token string and returns.
type Renderer interface { Render(ctx *Context) }
Renderer defines an http response renderer
Response is a wrapper for the http.ResponseWriter started set to true if response was written to then don't execute other handler
CloseNotify http.CloseNotifier
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.
WriteHeader sends an HTTP response header with status code, and sets `started` to true.
StatusCode sets the http response status code
Render sets the http status code
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4