context

package
v0.0.0-...-360893f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2016 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Usage:

ctx := context.Context{Request:req,ResponseWriter:rw}

Index

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) Abort

func (ctx *Context) Abort(status int, body string)

Abort stops this request. if beego.ErrorMaps exists, panic body.

func (*Context) GetCookie

func (ctx *Context) GetCookie(key string) string

Get cookie from request by a given key. It's alias of BeegoInput.Cookie.

func (*Context) Redirect

func (ctx *Context) Redirect(status int, localurl string)

Redirect does redirection to localurl with http header status code. It sends http response header directly.

func (*Context) SetCookie

func (ctx *Context) SetCookie(name string, value string, others ...interface{})

Set cookie for response. It's alias of BeegoOutput.Cookie.

func (*Context) WriteJson

func (ctx *Context) WriteJson(content []byte) error

json接口返回

func (*Context) WriteString

func (ctx *Context) WriteString(content string)

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 NewInput

func NewInput(req *http.Request) *EyeInput

NewInput return EyeInput generated by http.Request.

func (*EyeInput) AcceptsHtml

func (input *EyeInput) AcceptsHtml() bool

Checks if request accepts html response

func (*EyeInput) AcceptsJson

func (input *EyeInput) AcceptsJson() bool

Checks if request accepts json response

func (*EyeInput) AcceptsXml

func (input *EyeInput) AcceptsXml() bool

Checks if request accepts xml response

func (*EyeInput) Bind

func (input *EyeInput) 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") 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

func (input *EyeInput) Cookie(key string) string

Cookie returns request cookie item string by a given key. if non-existed, return empty string.

func (*EyeInput) CopyBody

func (input *EyeInput) CopyBody() []byte

CopyBody returns the raw request body data as bytes.

func (*EyeInput) Domain

func (input *EyeInput) Domain() string

Domain returns host name. Alias of Host method.

func (*EyeInput) GetData

func (input *EyeInput) GetData(key interface{}) interface{}

GetData returns the stored data in this context.

func (*EyeInput) Header

func (input *EyeInput) Header(key string) string

Header returns request header item string by a given string. if non-existed, return empty string.

func (*EyeInput) Host

func (input *EyeInput) Host() string

Host returns host name. if no host info in request, return localhost.

func (*EyeInput) IP

func (input *EyeInput) IP() string

IP returns request client ip. if in proxy, return first proxy id. if error, return 127.0.0.1.

func (*EyeInput) Is

func (input *EyeInput) Is(method string) bool

Is returns boolean of this request is on given method, such as Is("POST").

func (*EyeInput) IsAjax

func (input *EyeInput) IsAjax() bool

IsAjax returns boolean of this request is generated by ajax.

func (*EyeInput) IsDelete

func (input *EyeInput) IsDelete() bool

Is this a DELETE method request?

func (*EyeInput) IsGet

func (input *EyeInput) IsGet() bool

Is this a GET method request?

func (*EyeInput) IsHead

func (input *EyeInput) IsHead() bool

Is this a Head method request?

func (*EyeInput) IsOptions

func (input *EyeInput) IsOptions() bool

Is this a OPTIONS method request?

func (*EyeInput) IsPatch

func (input *EyeInput) IsPatch() bool

Is this a PATCH method request?

func (*EyeInput) IsPost

func (input *EyeInput) IsPost() bool

Is this a POST method request?

func (*EyeInput) IsPut

func (input *EyeInput) IsPut() bool

Is this a PUT method request?

func (*EyeInput) IsSecure

func (input *EyeInput) IsSecure() bool

IsSecure returns boolean of this request is in https.

func (*EyeInput) IsUpload

func (input *EyeInput) IsUpload() bool

IsUpload returns boolean of whether file uploads in this request or not..

func (*EyeInput) IsWebsocket

func (input *EyeInput) IsWebsocket() bool

IsWebsocket returns boolean of this request is in webSocket.

func (*EyeInput) Method

func (input *EyeInput) Method() string

Method returns http request method.

func (*EyeInput) Param

func (input *EyeInput) Param(key string) string

Param returns router param by a given key.

func (*EyeInput) ParseFormOrMulitForm

func (input *EyeInput) ParseFormOrMulitForm(maxMemory int64) error

parseForm or parseMultiForm based on Content-type

func (*EyeInput) Port

func (input *EyeInput) Port() int

Port returns request client port. when error or empty, return 80.

func (*EyeInput) Protocol

func (input *EyeInput) Protocol() string

Protocol returns request protocol name, such as HTTP/1.1 .

func (*EyeInput) Proxy

func (input *EyeInput) Proxy() []string

Proxy returns proxy client ips slice.

func (*EyeInput) Query

func (input *EyeInput) Query(key string) string

Query returns input data item string by a given string.

func (*EyeInput) Refer

func (input *EyeInput) Refer() string

Refer returns http referer header.

func (*EyeInput) Referer

func (input *EyeInput) Referer() string

Referer returns http referer header.

func (*EyeInput) Scheme

func (input *EyeInput) Scheme() string

Scheme returns request scheme as "http" or "https".

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) Site

func (input *EyeInput) Site() string

Site returns base site url as scheme://domain type.

func (*EyeInput) SubDomains

func (input *EyeInput) SubDomains() string

SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .

func (*EyeInput) Uri

func (input *EyeInput) Uri() string

Uri returns full request url with query string, fragment.

func (*EyeInput) Url

func (input *EyeInput) Url() string

Url returns request url path (without query string, fragment).

func (*EyeInput) UserAgent

func (input *EyeInput) UserAgent() string

UserAgent returns request client user agent string.

type EyeOutput

type EyeOutput struct {
	Context    *Context
	Status     int
	EnableGzip bool
}

EyeOutput does work for sending response header.

func NewOutput

func NewOutput() *EyeOutput

NewOutput returns new EyeOutput. it contains nothing now.

func (*EyeOutput) Body

func (output *EyeOutput) Body(content []byte)

Body sets response body content. if EnableGzip, compress content string. it sends out response body directly.

func (*EyeOutput) ContentType

func (output *EyeOutput) ContentType(ext string)

ContentType sets the content type from ext string. MIME type is given in mime package.

func (*EyeOutput) Cookie

func (output *EyeOutput) 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 (*EyeOutput) Download

func (output *EyeOutput) Download(file string, filename ...string)

Download forces response for download file. it prepares the download response header automatically.

func (*EyeOutput) Header

func (output *EyeOutput) Header(key, val string)

Header sets response header item string via given key.

func (*EyeOutput) IsCachable

func (output *EyeOutput) IsCachable(status int) bool

IsCachable returns boolean of this request is cached. HTTP 304 means cached.

func (*EyeOutput) IsClientError

func (output *EyeOutput) IsClientError(status int) bool

IsClient returns boolean of this request client sends error data. HTTP 4xx means forbidden.

func (*EyeOutput) IsEmpty

func (output *EyeOutput) IsEmpty(status int) bool

IsEmpty returns boolean of this request is empty. HTTP 201,204 and 304 means empty.

func (*EyeOutput) IsForbidden

func (output *EyeOutput) IsForbidden(status int) bool

IsForbidden returns boolean of this request is forbidden. HTTP 403 means forbidden.

func (*EyeOutput) IsNotFound

func (output *EyeOutput) IsNotFound(status int) bool

IsNotFound returns boolean of this request is not found. HTTP 404 means forbidden.

func (*EyeOutput) IsOk

func (output *EyeOutput) IsOk(status int) bool

IsOk returns boolean of this request runs well. HTTP 200 means ok.

func (*EyeOutput) IsRedirect

func (output *EyeOutput) IsRedirect(status int) bool

IsRedirect returns boolean of this request is redirection header. HTTP 301,302,307 means redirection.

func (*EyeOutput) IsServerError

func (output *EyeOutput) IsServerError(status int) bool

IsServerError returns boolean of this server handler errors. HTTP 5xx means server internal error.

func (*EyeOutput) IsSuccessful

func (output *EyeOutput) IsSuccessful(status int) bool

IsSuccessful returns boolean of this request runs successfully. HTTP 2xx means ok.

func (*EyeOutput) Json

func (output *EyeOutput) 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 (*EyeOutput) Jsonp

func (output *EyeOutput) Jsonp(data interface{}, hasIndent bool) error

Jsonp writes jsonp to response body.

func (*EyeOutput) SetStatus

func (output *EyeOutput) SetStatus(status int)

SetStatus sets response status code. It writes response header directly.

func (*EyeOutput) Xml

func (output *EyeOutput) Xml(data interface{}, hasIndent bool) error

Xml writes xml string to response body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL