Documentation ¶
Index ¶
- Constants
- func InitGzip(minLength, compressLevel int, methods []string)
- func ParseEncoding(r *http.Request) string
- func ParseForm(form url.Values, obj interface{}) error
- 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 BhojpurInput
- func (input *BhojpurInput) AcceptsHTML() bool
- func (input *BhojpurInput) AcceptsJSON() bool
- func (input *BhojpurInput) AcceptsXML() bool
- func (input *BhojpurInput) AcceptsYAML() bool
- func (input *BhojpurInput) Bind(dest interface{}, key string) error
- func (input *BhojpurInput) Cookie(key string) string
- func (input *BhojpurInput) CopyBody(MaxMemory int64) []byte
- func (input *BhojpurInput) Data() map[interface{}]interface{}
- func (input *BhojpurInput) Domain() string
- func (input *BhojpurInput) GetData(key interface{}) interface{}
- func (input *BhojpurInput) Header(key string) string
- func (input *BhojpurInput) Host() string
- func (input *BhojpurInput) IP() string
- func (input *BhojpurInput) Is(method string) bool
- func (input *BhojpurInput) IsAjax() bool
- func (input *BhojpurInput) IsDelete() bool
- func (input *BhojpurInput) IsGet() bool
- func (input *BhojpurInput) IsHead() bool
- func (input *BhojpurInput) IsOptions() bool
- func (input *BhojpurInput) IsPatch() bool
- func (input *BhojpurInput) IsPost() bool
- func (input *BhojpurInput) IsPut() bool
- func (input *BhojpurInput) IsSecure() bool
- func (input *BhojpurInput) IsUpload() bool
- func (input *BhojpurInput) IsWebsocket() bool
- func (input *BhojpurInput) Method() string
- func (input *BhojpurInput) Param(key string) string
- func (input *BhojpurInput) Params() map[string]string
- func (input *BhojpurInput) ParamsLen() int
- func (input *BhojpurInput) ParseFormOrMultiForm(maxMemory int64) error
- func (input *BhojpurInput) Port() int
- func (input *BhojpurInput) Protocol() string
- func (input *BhojpurInput) Proxy() []string
- func (input *BhojpurInput) Query(key string) string
- func (input *BhojpurInput) Refer() string
- func (input *BhojpurInput) Referer() string
- func (input *BhojpurInput) Reset(ctx *Context)
- func (input *BhojpurInput) ResetParams()
- func (input *BhojpurInput) Scheme() string
- func (input *BhojpurInput) Session(key interface{}) interface{}
- func (input *BhojpurInput) SetData(key, val interface{})
- func (input *BhojpurInput) SetParam(key, val string)
- func (input *BhojpurInput) Site() string
- func (input *BhojpurInput) SubDomains() string
- func (input *BhojpurInput) URI() string
- func (input *BhojpurInput) URL() string
- func (input *BhojpurInput) UserAgent() string
- type BhojpurOutput
- func (output *BhojpurOutput) Body(content []byte) error
- func (output *BhojpurOutput) ContentType(ext string)
- func (output *BhojpurOutput) Cookie(name string, value string, others ...interface{})
- func (output *BhojpurOutput) Download(file string, filename ...string)
- func (output *BhojpurOutput) Header(key, val string)
- func (output *BhojpurOutput) IsCachable() bool
- func (output *BhojpurOutput) IsClientError() bool
- func (output *BhojpurOutput) IsEmpty() bool
- func (output *BhojpurOutput) IsForbidden() bool
- func (output *BhojpurOutput) IsNotFound() bool
- func (output *BhojpurOutput) IsOk() bool
- func (output *BhojpurOutput) IsRedirect() bool
- func (output *BhojpurOutput) IsServerError() bool
- func (output *BhojpurOutput) IsSuccessful() bool
- func (output *BhojpurOutput) JSON(data interface{}, hasIndent bool, encoding bool) error
- func (output *BhojpurOutput) JSONP(data interface{}, hasIndent bool) error
- func (output *BhojpurOutput) Proto(data proto.Message) error
- func (output *BhojpurOutput) Reset(ctx *Context)
- func (output *BhojpurOutput) ServeFormatted(data interface{}, hasIndent bool, hasEncode ...bool) error
- func (output *BhojpurOutput) Session(name interface{}, value interface{})
- func (output *BhojpurOutput) SetStatus(status int)
- func (output *BhojpurOutput) XML(data interface{}, hasIndent bool) error
- func (output *BhojpurOutput) YAML(data interface{}) error
- type Context
- func (ctx *Context) Abort(status int, body string)
- func (ctx *Context) Bind(obj interface{}) error
- func (ctx *Context) BindForm(obj interface{}) error
- func (ctx *Context) BindJSON(obj interface{}) error
- func (ctx *Context) BindProtobuf(obj proto.Message) error
- func (ctx *Context) BindXML(obj interface{}) error
- func (ctx *Context) BindYAML(obj interface{}) error
- func (ctx *Context) CheckXSRFCookie() bool
- func (ctx *Context) GetCookie(key string) string
- func (ctx *Context) GetSecureCookie(Secret, key string) (string, bool)
- func (ctx *Context) JSONResp(data interface{}) error
- func (ctx *Context) ProtoResp(data proto.Message) error
- func (ctx *Context) Redirect(status int, localurl string)
- func (ctx *Context) RenderMethodResult(result interface{})
- func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)
- func (ctx *Context) Resp(data interface{}) error
- func (ctx *Context) Session() (store session.Store, err error)
- 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) XMLResp(data interface{}) error
- func (ctx *Context) XSRFToken(key string, expire int64) string
- func (ctx *Context) YamlResp(data interface{}) error
- type Renderer
- type Response
- type StatusCode
Constants ¶
const ( ApplicationJSON = "application/json" ApplicationXML = "application/xml" ApplicationForm = "application/x-www-form-urlencoded" ApplicationProto = "application/x-protobuf" ApplicationYAML = "application/x-yaml" TextXML = "text/xml" )
Commonly used mime-types
Variables ¶
This section is empty.
Functions ¶
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 BhojpurInput ¶
type BhojpurInput struct { Context *Context CruSession session.Store RequestBody []byte RunMethod string RunController reflect.Type // contains filtered or unexported fields }
BhojpurInput operates the http request header, data, cookie and body. Contains router params and current session.
func NewInput ¶
func NewInput() *BhojpurInput
NewInput returns the BhojpurInput generated by context.
func (*BhojpurInput) AcceptsHTML ¶
func (input *BhojpurInput) AcceptsHTML() bool
AcceptsHTML Checks if request accepts html response
func (*BhojpurInput) AcceptsJSON ¶
func (input *BhojpurInput) AcceptsJSON() bool
AcceptsJSON Checks if request accepts json response
func (*BhojpurInput) AcceptsXML ¶
func (input *BhojpurInput) AcceptsXML() bool
AcceptsXML Checks if request accepts xml response
func (*BhojpurInput) AcceptsYAML ¶
func (input *BhojpurInput) AcceptsYAML() bool
AcceptsYAML Checks if request accepts json response
func (*BhojpurInput) Bind ¶
func (input *BhojpurInput) 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=bhojpur var id int bhojpurInput.Bind(&id, "id") id ==123 var isok bool bhojpurInput.Bind(&isok, "isok") isok ==true var ft float64 bhojpurInput.Bind(&ft, "ft") ft ==1.2 ol := make([]int, 0, 2) bhojpurInput.Bind(&ol, "ol") ol ==[1 2] ul := make([]string, 0, 2) bhojpurInput.Bind(&ul, "ul") ul ==[str array] user struct{Name} bhojpurInput.Bind(&user, "user") user == {Name:"bhojpur"}
func (*BhojpurInput) Cookie ¶
func (input *BhojpurInput) Cookie(key string) string
Cookie returns request cookie item string by a given key. if non-existed, return empty string.
func (*BhojpurInput) CopyBody ¶
func (input *BhojpurInput) CopyBody(MaxMemory int64) []byte
CopyBody returns the raw request body data as bytes.
func (*BhojpurInput) Data ¶
func (input *BhojpurInput) Data() map[interface{}]interface{}
Data returns the implicit data in the input
func (*BhojpurInput) Domain ¶
func (input *BhojpurInput) Domain() string
Domain returns the host name (alias of host method)
func (*BhojpurInput) GetData ¶
func (input *BhojpurInput) GetData(key interface{}) interface{}
GetData returns the stored data in this context.
func (*BhojpurInput) Header ¶
func (input *BhojpurInput) Header(key string) string
Header returns request header item string by a given string. if non-existed, return empty string.
func (*BhojpurInput) Host ¶
func (input *BhojpurInput) Host() string
Host returns the host name. If no host info in request, return localhost.
func (*BhojpurInput) IP ¶
func (input *BhojpurInput) IP() string
IP returns request client ip. if in proxy, return first proxy id. if error, return RemoteAddr.
func (*BhojpurInput) Is ¶
func (input *BhojpurInput) Is(method string) bool
Is returns the boolean value of this request is on given method, such as Is("POST").
func (*BhojpurInput) IsAjax ¶
func (input *BhojpurInput) IsAjax() bool
IsAjax returns boolean of is this request generated by ajax.
func (*BhojpurInput) IsDelete ¶
func (input *BhojpurInput) IsDelete() bool
IsDelete Is this a DELETE method request?
func (*BhojpurInput) IsGet ¶
func (input *BhojpurInput) IsGet() bool
IsGet Is this a GET method request?
func (*BhojpurInput) IsHead ¶
func (input *BhojpurInput) IsHead() bool
IsHead Is this a Head method request?
func (*BhojpurInput) IsOptions ¶
func (input *BhojpurInput) IsOptions() bool
IsOptions Is this a OPTIONS method request?
func (*BhojpurInput) IsPatch ¶
func (input *BhojpurInput) IsPatch() bool
IsPatch Is this a PATCH method request?
func (*BhojpurInput) IsPost ¶
func (input *BhojpurInput) IsPost() bool
IsPost Is this a POST method request?
func (*BhojpurInput) IsPut ¶
func (input *BhojpurInput) IsPut() bool
IsPut Is this a PUT method request?
func (*BhojpurInput) IsSecure ¶
func (input *BhojpurInput) IsSecure() bool
IsSecure returns boolean of this request is in https.
func (*BhojpurInput) IsUpload ¶
func (input *BhojpurInput) IsUpload() bool
IsUpload returns boolean of whether file uploads in this request or not..
func (*BhojpurInput) IsWebsocket ¶
func (input *BhojpurInput) IsWebsocket() bool
IsWebsocket returns boolean of this request is in webSocket.
func (*BhojpurInput) Method ¶
func (input *BhojpurInput) Method() string
Method returns http request method.
func (*BhojpurInput) Param ¶
func (input *BhojpurInput) Param(key string) string
Param returns router param by a given key.
func (*BhojpurInput) Params ¶
func (input *BhojpurInput) Params() map[string]string
Params returns the map[key]value.
func (*BhojpurInput) ParamsLen ¶
func (input *BhojpurInput) ParamsLen() int
ParamsLen return the length of the params
func (*BhojpurInput) ParseFormOrMultiForm ¶
func (input *BhojpurInput) ParseFormOrMultiForm(maxMemory int64) error
ParseFormOrMultiForm parseForm or parseMultiForm based on Content-type
func (*BhojpurInput) Port ¶
func (input *BhojpurInput) Port() int
Port returns request client port. when error or empty, return 80.
func (*BhojpurInput) Protocol ¶
func (input *BhojpurInput) Protocol() string
Protocol returns the request protocol name, such as HTTP/1.1 .
func (*BhojpurInput) Proxy ¶
func (input *BhojpurInput) Proxy() []string
Proxy returns proxy client ips slice.
func (*BhojpurInput) Query ¶
func (input *BhojpurInput) Query(key string) string
Query returns input data item string by a given string.
func (*BhojpurInput) Refer ¶
func (input *BhojpurInput) Refer() string
Refer returns http referer header.
func (*BhojpurInput) Referer ¶
func (input *BhojpurInput) Referer() string
Referer returns http referer header.
func (*BhojpurInput) Reset ¶
func (input *BhojpurInput) Reset(ctx *Context)
Reset initializes the BhojpurInput
func (*BhojpurInput) ResetParams ¶
func (input *BhojpurInput) ResetParams()
ResetParams clears any of the input's params Used to clear parameters so they may be reset between filter passes.
func (*BhojpurInput) Scheme ¶
func (input *BhojpurInput) Scheme() string
Scheme returns the request scheme as "http" or "https".
func (*BhojpurInput) Session ¶
func (input *BhojpurInput) Session(key interface{}) interface{}
Session returns current session item value by a given key. if non-existed, return nil.
func (*BhojpurInput) SetData ¶
func (input *BhojpurInput) SetData(key, val interface{})
SetData stores data with given key in this context. This data is only available in this context.
func (*BhojpurInput) SetParam ¶
func (input *BhojpurInput) SetParam(key, val string)
SetParam sets the param with key and value
func (*BhojpurInput) Site ¶
func (input *BhojpurInput) Site() string
Site returns the base site url as scheme://domain type.
func (*BhojpurInput) SubDomains ¶
func (input *BhojpurInput) SubDomains() string
SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb
func (*BhojpurInput) URI ¶
func (input *BhojpurInput) URI() string
URI returns the full request url with query, string and fragment.
func (*BhojpurInput) URL ¶
func (input *BhojpurInput) URL() string
URL returns the request url path (without query, string and fragment).
func (*BhojpurInput) UserAgent ¶
func (input *BhojpurInput) UserAgent() string
UserAgent returns request client user agent string.
type BhojpurOutput ¶
BhojpurOutput does work for sending response header.
func NewOutput ¶
func NewOutput() *BhojpurOutput
NewOutput returns new BhojpurOutput. Empty when initialized
func (*BhojpurOutput) Body ¶
func (output *BhojpurOutput) Body(content []byte) error
Body sets the response body content. if EnableGzip, content is compressed. Sends out response body directly.
func (*BhojpurOutput) ContentType ¶
func (output *BhojpurOutput) ContentType(ext string)
ContentType sets the content type from ext string. MIME type is given in mime package.
func (*BhojpurOutput) Cookie ¶
func (output *BhojpurOutput) Cookie(name string, value string, others ...interface{})
Cookie sets a cookie value via given key. others: used to set a cookie's max age time, path,domain, secure and httponly.
func (*BhojpurOutput) Download ¶
func (output *BhojpurOutput) Download(file string, filename ...string)
Download forces response for download file. Prepares the download response header automatically.
func (*BhojpurOutput) Header ¶
func (output *BhojpurOutput) Header(key, val string)
Header sets response header item string via given key.
func (*BhojpurOutput) IsCachable ¶
func (output *BhojpurOutput) IsCachable() bool
IsCachable returns boolean of if this request is cached. HTTP 304 means cached.
func (*BhojpurOutput) IsClientError ¶
func (output *BhojpurOutput) IsClientError() bool
IsClientError returns boolean of if this request client sends error data. HTTP 4xx means client error.
func (*BhojpurOutput) IsEmpty ¶
func (output *BhojpurOutput) IsEmpty() bool
IsEmpty returns boolean of if this request is empty. HTTP 201,204 and 304 means empty.
func (*BhojpurOutput) IsForbidden ¶
func (output *BhojpurOutput) IsForbidden() bool
IsForbidden returns boolean of if this request is forbidden. HTTP 403 means forbidden.
func (*BhojpurOutput) IsNotFound ¶
func (output *BhojpurOutput) IsNotFound() bool
IsNotFound returns boolean of if this request is not found. HTTP 404 means not found.
func (*BhojpurOutput) IsOk ¶
func (output *BhojpurOutput) IsOk() bool
IsOk returns boolean of if this request was ok. HTTP 200 means ok.
func (*BhojpurOutput) IsRedirect ¶
func (output *BhojpurOutput) IsRedirect() bool
IsRedirect returns boolean of if this request is redirected. HTTP 301,302,307 means redirection.
func (*BhojpurOutput) IsServerError ¶
func (output *BhojpurOutput) IsServerError() bool
IsServerError returns boolean of if this server handler errors. HTTP 5xx means server internal error.
func (*BhojpurOutput) IsSuccessful ¶
func (output *BhojpurOutput) IsSuccessful() bool
IsSuccessful returns boolean of this request was successful. HTTP 2xx means ok.
func (*BhojpurOutput) JSON ¶
func (output *BhojpurOutput) JSON(data interface{}, hasIndent bool, encoding bool) error
JSON writes json to the response body. if encoding is true, it converts utf-8 to \u0000 type.
func (*BhojpurOutput) JSONP ¶
func (output *BhojpurOutput) JSONP(data interface{}, hasIndent bool) error
JSONP writes jsonp to the response body.
func (*BhojpurOutput) Proto ¶ added in v0.0.4
func (output *BhojpurOutput) Proto(data proto.Message) error
Proto writes protobuf to the response body.
func (*BhojpurOutput) Reset ¶
func (output *BhojpurOutput) Reset(ctx *Context)
Reset initializes BhojpurOutput
func (*BhojpurOutput) ServeFormatted ¶
func (output *BhojpurOutput) ServeFormatted(data interface{}, hasIndent bool, hasEncode ...bool) error
ServeFormatted serves YAML, XML or JSON, depending on the value of the Accept header
func (*BhojpurOutput) Session ¶
func (output *BhojpurOutput) Session(name interface{}, value interface{})
Session sets session item value with given key.
func (*BhojpurOutput) SetStatus ¶
func (output *BhojpurOutput) SetStatus(status int)
SetStatus sets the response status code. Writes response header directly.
func (*BhojpurOutput) XML ¶
func (output *BhojpurOutput) XML(data interface{}, hasIndent bool) error
XML writes xml string to the response body.
func (*BhojpurOutput) YAML ¶
func (output *BhojpurOutput) YAML(data interface{}) error
YAML writes yaml to the response body.
type Context ¶
type Context struct { Input *BhojpurInput Output *BhojpurOutput Request *http.Request ResponseWriter *Response // contains filtered or unexported fields }
Context Http request context struct including BhojpurInput, BhojpurOutput, http.Request and http.ResponseWriter. BhojpurInput and BhojpurOutput provides an api to operate request and response more easily.
func (*Context) BindProtobuf ¶ added in v0.0.4
BindProtobuf only read data from http request body
func (*Context) CheckXSRFCookie ¶
CheckXSRFCookie checks if the XSRF token in this request is valid or not. The token can be provided in the request header in the form "X-Xsrftoken" or "X-CsrfToken" or in form field value named as "_xsrf".
func (*Context) GetCookie ¶
GetCookie gets a cookie from a request for a given key. (Alias of BhojpurInput.Cookie)
func (*Context) GetSecureCookie ¶
GetSecureCookie gets a secure cookie from a request for a given key.
func (*Context) RenderMethodResult ¶
func (ctx *Context) RenderMethodResult(result interface{})
RenderMethodResult renders the return value of a controller method to the output
func (*Context) Reset ¶
func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)
Reset initializes Context, BhojpurInput and BhojpurOutput
func (*Context) Resp ¶ added in v0.0.4
Resp sends response based on the Accept Header By default response will be in JSON
func (*Context) SetSecureCookie ¶
SetSecureCookie sets a secure cookie for a response.
func (*Context) WriteString ¶
WriteString writes a string to response body.
type Renderer ¶
type Renderer interface {
Render(ctx *Context)
}
Renderer defines a http response renderer
type Response ¶
Response is a wrapper for the http.ResponseWriter Started: if true, response was already written to so the other handler will not be executed
func (*Response) CloseNotify ¶
CloseNotify http.CloseNotifier
func (*Response) Write ¶
Write writes the data to the connection as part of a HTTP reply, and sets `Started` to true. Started: if true, the response was already sent
func (*Response) WriteHeader ¶
WriteHeader sends a HTTP response header with status code, and sets `Started` to true.
type StatusCode ¶
type StatusCode int
StatusCode sets the HTTP response status code
const ( // BadRequest indicates HTTP error 400 BadRequest StatusCode = http.StatusBadRequest // NotFound indicates HTTP error 404 NotFound StatusCode = http.StatusNotFound )
func (StatusCode) Error ¶
func (s StatusCode) Error() string
func (StatusCode) Render ¶
func (s StatusCode) Render(ctx *Context)
Render sets the HTTP status code