Documentation ¶
Overview ¶
Usage:
ctx := context.Context{Request:req,ResponseWriter:rw}
Index ¶
- type Context
- func (ctx *Context) Abort(status int, body string)
- func (ctx *Context) GetCookie(key string) string
- func (ctx *Context) Redirect(status int, localurl string)
- func (ctx *Context) SetCookie(name string, value string, others ...interface{})
- func (ctx *Context) WriteJson(content []byte) error
- func (ctx *Context) WriteString(content string)
- type EyeInput
- func (input *EyeInput) AcceptsHtml() bool
- func (input *EyeInput) AcceptsJson() bool
- func (input *EyeInput) AcceptsXml() bool
- func (input *EyeInput) Bind(dest interface{}, key string) error
- func (input *EyeInput) Cookie(key string) string
- func (input *EyeInput) CopyBody() []byte
- func (input *EyeInput) Domain() string
- func (input *EyeInput) GetData(key interface{}) interface{}
- func (input *EyeInput) Header(key string) string
- func (input *EyeInput) Host() string
- func (input *EyeInput) IP() string
- func (input *EyeInput) Is(method string) bool
- func (input *EyeInput) IsAjax() bool
- func (input *EyeInput) IsDelete() bool
- func (input *EyeInput) IsGet() bool
- func (input *EyeInput) IsHead() bool
- func (input *EyeInput) IsOptions() bool
- func (input *EyeInput) IsPatch() bool
- func (input *EyeInput) IsPost() bool
- func (input *EyeInput) IsPut() bool
- func (input *EyeInput) IsSecure() bool
- func (input *EyeInput) IsUpload() bool
- func (input *EyeInput) IsWebsocket() bool
- func (input *EyeInput) Method() string
- func (input *EyeInput) Param(key string) string
- func (input *EyeInput) ParseFormOrMulitForm(maxMemory int64) error
- func (input *EyeInput) Port() int
- func (input *EyeInput) Protocol() string
- func (input *EyeInput) Proxy() []string
- func (input *EyeInput) Query(key string) string
- func (input *EyeInput) Refer() string
- func (input *EyeInput) Referer() string
- func (input *EyeInput) Scheme() string
- func (input *EyeInput) SetData(key, val interface{})
- func (input *EyeInput) Site() string
- func (input *EyeInput) SubDomains() string
- func (input *EyeInput) Uri() string
- func (input *EyeInput) Url() string
- func (input *EyeInput) UserAgent() string
- type EyeOutput
- func (output *EyeOutput) Body(content []byte)
- func (output *EyeOutput) ContentType(ext string)
- func (output *EyeOutput) Cookie(name string, value string, others ...interface{})
- func (output *EyeOutput) Download(file string, filename ...string)
- func (output *EyeOutput) Header(key, val string)
- func (output *EyeOutput) IsCachable(status int) bool
- func (output *EyeOutput) IsClientError(status int) bool
- func (output *EyeOutput) IsEmpty(status int) bool
- func (output *EyeOutput) IsForbidden(status int) bool
- func (output *EyeOutput) IsNotFound(status int) bool
- func (output *EyeOutput) IsOk(status int) bool
- func (output *EyeOutput) IsRedirect(status int) bool
- func (output *EyeOutput) IsServerError(status int) bool
- func (output *EyeOutput) IsSuccessful(status int) bool
- func (output *EyeOutput) Json(data interface{}, hasIndent bool, coding bool) error
- func (output *EyeOutput) Jsonp(data interface{}, hasIndent bool) error
- func (output *EyeOutput) SetStatus(status int)
- func (output *EyeOutput) Xml(data interface{}, hasIndent bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Input *EyeInput Output *EyeOutput Request *http.Request ResponseWriter http.ResponseWriter }
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) GetCookie ¶
Get cookie from request by a given key. It's alias of BeegoInput.Cookie.
func (*Context) Redirect ¶
Redirect does redirection to localurl with http header status code. It sends http response header directly.
func (*Context) WriteString ¶
Write string to response body. it sends response body.
type EyeInput ¶
type EyeInput 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 }
EyeInput operates the http request header, data, cookie and body. it also contains router params and current session.
func (*EyeInput) AcceptsHtml ¶
Checks if request accepts html response
func (*EyeInput) AcceptsJson ¶
Checks if request accepts json response
func (*EyeInput) AcceptsXml ¶
Checks if request accepts xml response
func (*EyeInput) Bind ¶
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"}
func (*EyeInput) Cookie ¶
Cookie returns request cookie item string by a given key. if non-existed, return empty string.
func (*EyeInput) GetData ¶
func (input *EyeInput) GetData(key interface{}) interface{}
GetData returns the stored data in this context.
func (*EyeInput) Header ¶
Header returns request header item string by a given string. if non-existed, return empty string.
func (*EyeInput) IP ¶
IP returns request client ip. if in proxy, return first proxy id. if error, return 127.0.0.1.
func (*EyeInput) IsUpload ¶
IsUpload returns boolean of whether file uploads in this request or not..
func (*EyeInput) IsWebsocket ¶
IsWebsocket returns boolean of this request is in webSocket.
func (*EyeInput) ParseFormOrMulitForm ¶
parseForm or parseMultiForm based on Content-type
func (*EyeInput) SetData ¶
func (input *EyeInput) SetData(key, val interface{})
SetData stores data with given key in this context. This data are only available in this context.
func (*EyeInput) SubDomains ¶
SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .
type EyeOutput ¶
EyeOutput does work for sending response header.
func NewOutput ¶
func NewOutput() *EyeOutput
NewOutput returns new EyeOutput. it contains nothing now.
func (*EyeOutput) Body ¶
Body sets response body content. if EnableGzip, compress content string. it sends out response body directly.
func (*EyeOutput) ContentType ¶
ContentType sets the content type from ext string. MIME type is given in mime package.
func (*EyeOutput) Cookie ¶
Cookie sets cookie value via given key. others are ordered as cookie's max age time, path,domain, secure and httponly.
func (*EyeOutput) Download ¶
Download forces response for download file. it prepares the download response header automatically.
func (*EyeOutput) IsCachable ¶
IsCachable returns boolean of this request is cached. HTTP 304 means cached.
func (*EyeOutput) IsClientError ¶
IsClient returns boolean of this request client sends error data. HTTP 4xx means forbidden.
func (*EyeOutput) IsEmpty ¶
IsEmpty returns boolean of this request is empty. HTTP 201,204 and 304 means empty.
func (*EyeOutput) IsForbidden ¶
IsForbidden returns boolean of this request is forbidden. HTTP 403 means forbidden.
func (*EyeOutput) IsNotFound ¶
IsNotFound returns boolean of this request is not found. HTTP 404 means forbidden.
func (*EyeOutput) IsRedirect ¶
IsRedirect returns boolean of this request is redirection header. HTTP 301,302,307 means redirection.
func (*EyeOutput) IsServerError ¶
IsServerError returns boolean of this server handler errors. HTTP 5xx means server internal error.
func (*EyeOutput) IsSuccessful ¶
IsSuccessful returns boolean of this request runs successfully. HTTP 2xx means ok.
func (*EyeOutput) Json ¶
Json writes json to response body. if coding is true, it converts utf-8 to \u0000 type.