Documentation ¶
Overview ¶
Package context provide the context utils Usage:
import "github.com/goasana/asana/context" ctx := Context{HTTPRequest:req,ResponseWriter:rw} more docs http://asana.me/docs/module/md
Index ¶
- Constants
- func InitGzip(minLength, compressLevel int, methods []string)
- func ParseEncoding(r *http.Request) string
- 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 Context
- func (res Context) Abort(body string) error
- func (req Context) Accepts(contentTypes ...string) bool
- func (req Context) AcceptsHTML() bool
- func (req Context) AcceptsJSON() bool
- func (req Context) AcceptsJSONP() bool
- func (req Context) AcceptsMSGPACK() bool
- func (req Context) AcceptsProtoBuf() bool
- func (req Context) AcceptsXML() bool
- func (req Context) AcceptsYAML() bool
- func (req Context) BindForm(dest interface{}, key string) error
- func (res Context) Blob(contentType string, b []byte) error
- func (res Context) Body(content []byte) error
- func (ctx *Context) CheckXSRFCookie() bool
- func (ctx *Context) ContentType(ext string) *Context
- func (req Context) Cookie(key string) string
- func (req Context) CopyBody(MaxMemory int64) []byte
- func (req Context) Data() map[interface{}]interface{}
- func (ctx *Context) DelSession(name interface{})
- func (req Context) Domain() string
- func (res Context) Download(file string, filename ...string)
- func (ctx *Context) GetBool(key string, def ...bool) (bool, error)
- func (res Context) GetData() map[interface{}]interface{}
- func (ctx *Context) GetFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (ctx *Context) GetFiles(key string) ([]*multipart.FileHeader, error)
- func (req Context) GetFlash(key interface{}) interface{}
- func (ctx *Context) GetFloat(key string, def ...float64) (float64, error)
- func (ctx *Context) GetInt(key string, def ...int) (int, error)
- func (ctx *Context) GetInt16(key string, def ...int16) (int16, error)
- func (ctx *Context) GetInt32(key string, def ...int32) (int32, error)
- func (ctx *Context) GetInt64(key string, def ...int64) (int64, error)
- func (ctx *Context) GetInt8(key string, def ...int8) (int8, error)
- func (res Context) GetItemData(item string) interface{}
- func (req Context) GetJWT() (string, error)
- func (req Context) GetLanguage(def ...string) string
- func (res Context) GetSecureCookie(Secret, key string) (string, bool)
- func (ctx *Context) GetSession(name interface{}) interface{}
- func (res Context) GetStatus() int
- func (ctx *Context) GetString(key string, def ...string) string
- func (ctx *Context) GetStrings(key string, def ...[]string) []string
- func (ctx *Context) GetUint16(key string, def ...uint16) (uint16, error)
- func (ctx *Context) GetUint32(key string, def ...uint32) (uint32, error)
- func (ctx *Context) GetUint64(key string, def ...uint64) (uint64, error)
- func (ctx *Context) GetUint8(key string, def ...uint8) (uint8, error)
- func (res Context) HTML(html string) error
- func (res Context) HTMLBlob(data []byte) error
- func (req Context) Header(key string) string
- func (req Context) Host() string
- func (req Context) IP() string
- func (ctx *Context) Input() url.Values
- func (req Context) Is(method string) bool
- func (ctx *Context) IsAjax() bool
- func (res Context) IsCachable() bool
- func (res Context) IsClientError() bool
- func (req Context) IsDelete() bool
- func (res Context) IsEmpty() bool
- func (res Context) IsForbidden() bool
- func (req Context) IsGet() bool
- func (req Context) IsHead() bool
- func (res Context) IsNotFound() bool
- func (res Context) IsOk() bool
- func (req Context) IsOptions() bool
- func (req Context) IsPatch() bool
- func (req Context) IsPost() bool
- func (req Context) IsPut() bool
- func (res Context) IsRedirect() bool
- func (req Context) IsSecure() bool
- func (res Context) IsServerError() bool
- func (res Context) IsSuccessful() bool
- func (req Context) IsUpload() bool
- func (req Context) IsWebsocket() bool
- func (res Context) JSON(data interface{}, hasIndent bool, encoding bool) error
- func (res Context) JSONP(data interface{}, hasIndent bool) error
- func (req Context) Method() string
- func (res Context) NoContent() error
- func (req Context) Param(key string) string
- func (req Context) Params() map[string]string
- func (req Context) ParamsLen() int
- func (req Context) ParseFormOrMultiForm(maxMemory int64) error
- func (req Context) Port() int
- func (res Context) ProtoBuf(data interface{}) error
- func (req Context) Protocol() string
- func (req Context) Proxy() []string
- func (res Context) PutData(key interface{}, data interface{}) Response
- func (req Context) Query(key string) string
- func (res Context) Redirect(url string) error
- func (req Context) Refer() string
- func (req Context) Referer() string
- func (res Context) RenderMethodResult(result interface{}) Response
- func (ctx *Context) Request() Request
- func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)
- func (req Context) ResetParams() Request
- func (ctx *Context) Response() Response
- func (ctx *Context) SaveToFile(fromFile, toFile string) error
- func (req Context) Scheme() string
- func (res Context) ServeFormatted(encoding ...bool) error
- func (res Context) ServeHTML() error
- func (res Context) ServeJSON(encoding ...bool) error
- func (res Context) ServeJSONP() error
- func (res Context) ServeProtoBuf() error
- func (res Context) ServeText() error
- func (res Context) ServeXML() error
- func (res Context) ServeYAML() error
- func (ctx *Context) Session(key interface{}) interface{}
- func (res Context) SetBody(data interface{}) Response
- func (res Context) SetCookie(name string, value string, others ...interface{}) Response
- func (res Context) SetData(data map[interface{}]interface{}) Response
- func (req Context) SetFlash(key, val interface{})
- func (res Context) SetHeader(key, val string) Response
- func (req Context) SetParam(key, val string)
- func (res Context) SetSecureCookie(Secret, name, value string, others ...interface{}) Response
- func (ctx *Context) SetSession(name interface{}, value interface{}) *Context
- func (res Context) SetStatus(status int) Response
- func (res Context) SetXSRFToken(key string, expire int64) string
- func (req Context) Site() string
- func (res Context) Stream(contentType string, r io.Reader) (err error)
- func (req Context) SubDomains() string
- func (res Context) Text(data string) error
- func (res Context) TextBlob(data []byte) (err error)
- func (req Context) URI() string
- func (req Context) URL() string
- func (req Context) UserAgent() string
- func (res Context) XML(data interface{}, hasIndent bool) error
- func (ctx *Context) XSRFFormHTML() string
- func (res Context) XSRFToken() string
- func (res Context) YAML(data interface{}) error
- type Renderer
- type Request
- type Response
- type ResponseWriter
- type StatusCode
Constants ¶
const ( ApplicationHTML = "application/xhtml+xml" ApplicationJSON = "application/json" ApplicationJSONP = "application/javascript" ApplicationXML = "application/xml" ApplicationYAML = "application/x-yaml" ApplicationProtoBuf = "application/x-protobuf" ApplicationMSGPack = "application/x-msgpack" TextXML = "text/xml" TextHTML = "text/html" TextPlain = "text/plain" )
commonly used mime-types
const ( HeaderAccept = "Accept" HeaderReferer = "Referer" HeaderUserAgent = "User-Agent" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" HeaderExpires = "Expires" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderCacheControl = "Cache-Control" HeaderPragma = "Pragma" HeaderContentDisposition = "Content-Disposition" HeaderContentDescription = "Content-Description" HeaderContentEncoding = "Content-Encoding" HeaderContentTransferEncoding = "Content-Transfer-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXRealIP = "X-Real-IP" HeaderXRequestID = "X-Request-ID" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" // Access control HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderXCSRFToken = "X-CSRF-Token" )
Headers
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 Context ¶
type Context struct { CruSession session.Store // xsrf data XSRFExpire int EnableXSRF bool IsPro bool // contains filtered or unexported fields }
Context Http request context struct including asanaRequest, asanaResponse, http.HTTPRequest and http.ResponseWriter. asanaRequest and asanaResponse provides some api to operate request and response more easily.
func NewContext ¶
func NewContext() *Context
NewContext return the Context with Request and ResponseWriter
func (Context) AcceptsHTML ¶
func (req Context) AcceptsHTML() bool
AcceptsHTML Checks if request accepts html response
func (Context) AcceptsJSON ¶
func (req Context) AcceptsJSON() bool
AcceptsJSON Checks if request accepts json response
func (Context) AcceptsJSONP ¶
func (req Context) AcceptsJSONP() bool
AcceptsJSONP Checks if request accepts jsonp response
func (Context) AcceptsMSGPACK ¶
func (req Context) AcceptsMSGPACK() bool
AcceptsMSGPACK Checks if request accepts msgpack response
func (Context) AcceptsProtoBuf ¶
func (req Context) AcceptsProtoBuf() bool
AcceptsProtoBuf Checks if request accepts protobuf response
func (Context) AcceptsXML ¶
func (req Context) AcceptsXML() bool
AcceptsXML Checks if request accepts xml response
func (Context) AcceptsYAML ¶
func (req Context) AcceptsYAML() bool
AcceptsYAML Checks if request accepts yaml response
func (Context) BindForm ¶
BindForm 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=asana var id int asanaInput.BindForm(&id, "id") id ==123 var isok bool asanaInput.BindForm(&isok, "isok") isok ==true var ft float64 asanaInput.BindForm(&ft, "ft") ft ==1.2 ol := make([]int, 0, 2) asanaInput.BindForm(&ol, "ol") ol ==[1 2] ul := make([]string, 0, 2) asanaInput.BindForm(&ul, "ul") ul ==[str array] user struct{Name} asanaInput.BindForm(&user, "user") user == {Name:"asana"}
func (Context) Body ¶
Body sets.Body content. if EnableGzip, compress content string. it sends out.Body directly.
func (*Context) CheckXSRFCookie ¶
CheckXSRFCookie checks xsrf token in this request is valid or not. the token can provided in request header "X-CsrfToken" or in form field value named as "_xsrf".
func (*Context) ContentType ¶
ContentType sets the content type from ext string. MIME type is given in mime package.
func (Context) Cookie ¶
Cookie returns request cookie item string by a given key. if non-existed, return empty string.
func (Context) Data ¶
func (req Context) Data() map[interface{}]interface{}
data return the implicit data in the input
func (*Context) DelSession ¶
func (ctx *Context) DelSession(name interface{})
DelSession removes value from session.
func (Context) Domain ¶
func (req Context) Domain() string
Domain returns host name. Alias of Host method.
func (Context) Download ¶
Download forces response for download file. it prepares the download.Header automatically.
func (*Context) GetBool ¶
GetBool returns input value as bool or the default value while it's present and input is blank.
func (Context) GetData ¶
func (res Context) GetData() map[interface{}]interface{}
GetData set the data
func (*Context) GetFile ¶
GetFile returns the file data in file upload field named as key. it returns the first one of multi-uploaded files.
func (*Context) GetFiles ¶
func (ctx *Context) GetFiles(key string) ([]*multipart.FileHeader, error)
GetFiles return multi-upload files files, err:=c.GetFiles("myfiles")
if err != nil { http.Error(w, err.Error(), http.StatusNoContent) return }
for i, _ := range files { //for each fileheader, get a handle to the actual file file, err := files[i].Open() defer file.Close() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } //create destination file making sure the path is writeable. dst, err := os.Create("upload/" + files[i].Filename) defer dst.Close() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } //copy the uploaded file to the destination file if _, err := io.Copy(dst, file); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } }
GetFiles get files
func (Context) GetFlash ¶
func (req Context) GetFlash(key interface{}) interface{}
GetFlash returns the stored data in this context.
func (*Context) GetFloat ¶
GetFloat returns input value as float64 or the default value while it's present and input is blank.
func (*Context) GetInt ¶
GetInt returns input as an int or the default value while it's present and input is blank
func (*Context) GetInt16 ¶
GetInt16 returns input as an int16 or the default value while it's present and input is blank
func (*Context) GetInt32 ¶
GetInt32 returns input as an int32 or the default value while it's present and input is blank
func (*Context) GetInt64 ¶
GetInt64 returns input value as int64 or the default value while it's present and input is blank.
func (*Context) GetInt8 ¶
GetInt8 return input as an int8 or the default value while it's present and input is blank
func (Context) GetItemData ¶
func (res Context) GetItemData(item string) interface{}
GetItemData get item in data
func (Context) GetLanguage ¶
GetLanguage get the language accepted
func (Context) GetSecureCookie ¶
GetSecureCookie Get secure cookie from request by a given key.
func (*Context) GetSession ¶
func (ctx *Context) GetSession(name interface{}) interface{}
GetSession gets value from session.
func (Context) GetStatus ¶
func (res Context) GetStatus() int
GetStatus obtain the current status code
func (*Context) GetString ¶
GetString returns the input value by key string or the default value while it's present and input is blank
func (*Context) GetStrings ¶
GetStrings returns the input string slice by key string or the default value while it's present and input is blank it's designed for multi-value input field such as checkbox(input[type=checkbox]), multi-selection.
func (*Context) GetUint16 ¶
GetUint16 returns input as an uint16 or the default value while it's present and input is blank
func (*Context) GetUint32 ¶
GetUint32 returns input as an uint32 or the default value while it's present and input is blank
func (*Context) GetUint64 ¶
GetUint64 returns input value as uint64 or the default value while it's present and input is blank.
func (*Context) GetUint8 ¶
GetUint8 return input as an uint8 or the default value while it's present and input is blank
func (Context) Header ¶
Header returns request header item string by a given string. if non-existed, return empty string.
func (Context) Host ¶
func (req Context) Host() string
Host returns host name. if no host info in request, return localhost.
func (Context) IP ¶
func (req Context) IP() string
IP returns request client ip. if in proxy, return first proxy id. if error, return RemoteAddr.
func (*Context) Input ¶
Input Request returns the input data map from POST or PUT request body and query string.
func (Context) IsCachable ¶
func (res Context) IsCachable() bool
IsCachable returns boolean of this request is cached. HTTP 304 means cached.
func (Context) IsClientError ¶
func (res Context) IsClientError() bool
IsClientError returns boolean of this request client sends error data. HTTP 4xx means client error.
func (Context) IsDelete ¶
func (req Context) IsDelete() bool
IsDelete Is this a DELETE method request?
func (Context) IsEmpty ¶
func (res Context) IsEmpty() bool
IsEmpty returns boolean of this request is empty. HTTP 201,204 and 304 means empty.
func (Context) IsForbidden ¶
func (res Context) IsForbidden() bool
IsForbidden returns boolean of this request is forbidden. HTTP 403 means forbidden.
func (Context) IsNotFound ¶
func (res Context) IsNotFound() bool
IsNotFound returns boolean of this request is not found. HTTP 404 means not found.
func (Context) IsOk ¶
func (res Context) IsOk() bool
IsOk returns boolean of this request runs well. HTTP 200 means ok.
func (Context) IsOptions ¶
func (req Context) IsOptions() bool
IsOptions Is this a OPTIONS method request?
func (Context) IsRedirect ¶
func (res Context) IsRedirect() bool
IsRedirect returns boolean of this request is redirection header. HTTP 301,302,307 means redirection.
func (Context) IsSecure ¶
func (req Context) IsSecure() bool
IsSecure returns boolean of this request is in https.
func (Context) IsServerError ¶
func (res Context) IsServerError() bool
IsServerError returns boolean of this server handler errors. HTTP 5xx means server internal error.
func (Context) IsSuccessful ¶
func (res Context) IsSuccessful() bool
IsSuccessful returns boolean of this request runs successfully. HTTP 2xx means ok.
func (Context) IsUpload ¶
func (req Context) IsUpload() bool
IsUpload returns boolean of whether file uploads in this request or not..
func (Context) IsWebsocket ¶
func (req Context) IsWebsocket() bool
IsWebsocket returns boolean of this request is in webSocket.
func (Context) JSON ¶
JSON writes json to.Bodyres. if encoding is true, it converts utf-8 to \u0000 type.
func (Context) ParamsLen ¶
func (req Context) ParamsLen() int
ParamsLen return the length of the params
func (Context) ParseFormOrMultiForm ¶
ParseFormOrMultiForm parseForm or parseMultiForm based on Content-type
func (Context) Port ¶
func (req Context) Port() int
Port returns request client port. when error or empty, return 80.
func (Context) ProtoBuf ¶
func (res Context) ProtoBuf(data interface{}) error
ProtoBuf writes protobuf to.Body.
func (Context) Protocol ¶
func (req Context) Protocol() string
Protocol returns request protocol name, such as HTTP/1.1 .
func (Context) PutData ¶
func (res Context) PutData(key interface{}, data interface{}) Response
PutData set the data depending on the accepted
func (Context) RenderMethodResult ¶
func (res Context) RenderMethodResult(result interface{}) Response
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 init Context, asanaRequest and asanaResponse
func (Context) ResetParams ¶
func (req Context) ResetParams() Request
ResetParams clears any of the input's Params This function is used to clear parameters so they may be reset between filter passes.
func (*Context) SaveToFile ¶
SaveToFile saves uploaded file to new path. it only operates the first one of mutil-upload form file field.
func (Context) Scheme ¶
func (req Context) Scheme() string
Scheme returns request scheme as "http" or "https".
func (Context) ServeFormatted ¶
ServeFormatted serve YAML, XML, JSON, ProtoBuffer, Html or Text, depending on the value of the Accept header
func (Context) ServeJSONP ¶
func (res Context) ServeJSONP() error
ServeJSONP sends a jsonp response.
func (Context) ServeProtoBuf ¶
func (res Context) ServeProtoBuf() error
ServeProtoBuf sends protobuf response.
func (Context) ServeText ¶
func (res Context) ServeText() error
ServeText sends text plain response.
func (*Context) Session ¶
func (ctx *Context) Session(key interface{}) interface{}
Session returns current session item value by a given key. if non-existed, return nil.
func (Context) SetBody ¶
func (res Context) SetBody(data interface{}) Response
SetFlash set the data depending on the accepted
func (Context) SetCookie ¶
Cookie sets cookie value via given key. others are ordered as cookie's max age time, path,domain, secure and httponly.
func (Context) SetData ¶
func (res Context) SetData(data map[interface{}]interface{}) Response
SetData set the data
func (Context) SetFlash ¶
func (req Context) SetFlash(key, val interface{})
SetFlash stores data with given key in this context. This data are only available in this context.
func (Context) SetParam ¶
func (req Context) SetParam(key, val string)
SetParam will set the param with key and value
func (Context) SetSecureCookie ¶
SetSecureCookie Set Secure cookie for response.
func (*Context) SetSession ¶
SetSession puts value into session.
func (Context) SetXSRFToken ¶
SetXSRFToken creates a xsrf token string and returns.
func (Context) Site ¶
func (req Context) Site() string
Site returns base site url as scheme://domain type.
func (Context) SubDomains ¶
func (req Context) SubDomains() string
SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .
func (Context) URI ¶
func (req Context) URI() string
URI returns full request url with query string, fragment.
func (Context) URL ¶
func (req Context) URL() string
URL returns request url path (without query string, fragment).
func (Context) UserAgent ¶
func (req Context) UserAgent() string
UserAgent returns request client user agent string.
func (*Context) XSRFFormHTML ¶
XSRFFormHTML writes an input field contains xsrf token value.
type Renderer ¶
type Renderer interface {
Render(ctx *Context)
}
Renderer defines an http response renderer
type Request ¶
type Request interface { Header(head string) string GetLanguage(def ...string) string Reset(ctx *Context) Protocol() string URI() string URL() string Site() string Scheme() string Domain() string Host() string Method() string Is(method string) bool IsGet() bool IsPost() bool IsHead() bool IsOptions() bool IsPut() bool IsDelete() bool IsPatch() bool IsAjax() bool IsSecure() bool IsWebsocket() bool IsUpload() bool Accepts(contentTypes ...string) bool AcceptsHTML() bool AcceptsXML() bool AcceptsJSON() bool AcceptsJSONP() bool AcceptsYAML() bool AcceptsProtoBuf() bool IP() string Proxy() []string Referer() string Refer() string SubDomains() string Port() int UserAgent() string ParamsLen() int Param(key string) string Params() map[string]string SetParam(key, val string) ResetParams() Request Cookie(key string) string CopyBody(MaxMemory int64) []byte Data() map[interface{}]interface{} Query(key string) string GetFlash(key interface{}) interface{} SetFlash(key, val interface{}) ParseFormOrMultiForm(maxMemory int64) error BindForm(dest interface{}, key string) error }
Request methods of req
type Response ¶
type Response interface { Reset(res *Context) Response SetCookie(name string, value string, others ...interface{}) Response GetStatus() int SetStatus(status int) Response IsCachable() bool IsEmpty() bool IsOk() bool IsSuccessful() bool IsRedirect() bool IsForbidden() bool IsNotFound() bool IsClientError() bool IsServerError() bool JSON(data interface{}, hasIndent bool, encoding bool) error ProtoBuf(data interface{}) error YAML(data interface{}) error JSONP(data interface{}, hasIndent bool) error XML(data interface{}, hasIndent bool) error SetXSRFToken(key string, expire int64) string GetSecureCookie(Secret, key string) (string, bool) SetSecureCookie(Secret, name, value string, others ...interface{}) Response RenderMethodResult(result interface{}) Response Download(file string, filename ...string) SetBody(data interface{}) Response PutData(key interface{}, data interface{}) Response SetData(data map[interface{}]interface{}) Response GetData() map[interface{}]interface{} Abort(body string) error Redirect(url string) error Body(content []byte) error NoContent() error Text(data string) error TextBlob(data []byte) error HTML(html string) error HTMLBlob(data []byte) error Blob(contentType string, b []byte) error Stream(contentType string, r io.Reader) error ServeFormatted(encoding ...bool) error }
Response actions for response
type ResponseWriter ¶
ResponseWriter is a wrapper for the http.ResponseWriter started set to true if response was written to then don't execute other handler
func (*ResponseWriter) Hijack ¶
func (r *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack hijacker for http
func (*ResponseWriter) Pusher ¶
func (r *ResponseWriter) Pusher() (pusher http.Pusher)
Pusher http.Pusher
func (*ResponseWriter) Write ¶
func (r *ResponseWriter) Write(p []byte) (int, error)
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.
func (*ResponseWriter) WriteHeader ¶
func (r *ResponseWriter) WriteHeader(code int)
WriteHeader sends an HTTP.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