context

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: Apache-2.0 Imports: 34 Imported by: 0

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

View Source
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

View Source
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 InitGzip

func InitGzip(minLength, compressLevel int, methods []string)

InitGzip init the gzipcompress

func ParseEncoding

func ParseEncoding(r *http.Request) string

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

func WriteBody

func WriteBody(encoding string, writer io.Writer, content []byte) (bool, string, error)

WriteBody reads writes content to writer by the specific encoding(gzip/brotli/deflate)

func WriteFile

func WriteFile(encoding string, writer io.Writer, file *os.File) (bool, string, error)

WriteFile reads from file and writes to writer by the specific encoding(gzip/brotli/deflate)

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

func (res Context) Abort(body string) error

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

func (Context) Accepts

func (req Context) Accepts(contentTypes ...string) bool

AcceptsHTML Checks if request accepts html response

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) AcceptsMSGPack added in v1.13.0

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) AcceptsTextPlain added in v1.13.0

func (req Context) AcceptsTextPlain() bool

AcceptsTextPlain Checks if request accepts txt 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

func (req Context) BindForm(dest interface{}, key string) error

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

func (res Context) Blob(contentType string, b []byte) error

Blob writes []byte to.Body.

func (Context) Body

func (res Context) Body(content []byte) error

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

func (*Context) CheckXSRFCookie

func (ctx *Context) CheckXSRFCookie() bool

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

func (ctx *Context) ContentType(ext string) *Context

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

func (Context) Cookie

func (req Context) Cookie(key string) string

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

func (Context) CopyBody

func (req Context) CopyBody(MaxMemory int64) []byte

CopyBody returns the raw request body data as bytes.

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

func (res Context) Download(file string, filename ...string)

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

func (*Context) GetBool

func (ctx *Context) GetBool(key string, def ...bool) (bool, error)

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

func (ctx *Context) GetFile(key string) (multipart.File, *multipart.FileHeader, error)

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

func (ctx *Context) GetFloat(key string, def ...float64) (float64, error)

GetFloat returns input value as float64 or the default value while it's present and input is blank.

func (*Context) GetInt

func (ctx *Context) GetInt(key string, def ...int) (int, error)

GetInt returns input as an int or the default value while it's present and input is blank

func (*Context) GetInt16

func (ctx *Context) GetInt16(key string, def ...int16) (int16, error)

GetInt16 returns input as an int16 or the default value while it's present and input is blank

func (*Context) GetInt32

func (ctx *Context) GetInt32(key string, def ...int32) (int32, error)

GetInt32 returns input as an int32 or the default value while it's present and input is blank

func (*Context) GetInt64

func (ctx *Context) GetInt64(key string, def ...int64) (int64, error)

GetInt64 returns input value as int64 or the default value while it's present and input is blank.

func (*Context) GetInt8

func (ctx *Context) GetInt8(key string, def ...int8) (int8, error)

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

func (req Context) GetJWT() (string, error)

GetJWT get token

func (Context) GetLanguage

func (req Context) GetLanguage(def ...string) string

GetLanguage get the language accepted

func (Context) GetSecureCookie

func (res Context) GetSecureCookie(Secret, key string) (string, bool)

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

func (ctx *Context) GetString(key string, def ...string) string

GetString returns the input value by key string or the default value while it's present and input is blank

func (*Context) GetStrings

func (ctx *Context) GetStrings(key string, def ...[]string) []string

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

func (ctx *Context) GetUint16(key string, def ...uint16) (uint16, error)

GetUint16 returns input as an uint16 or the default value while it's present and input is blank

func (*Context) GetUint32

func (ctx *Context) GetUint32(key string, def ...uint32) (uint32, error)

GetUint32 returns input as an uint32 or the default value while it's present and input is blank

func (*Context) GetUint64

func (ctx *Context) GetUint64(key string, def ...uint64) (uint64, error)

GetUint64 returns input value as uint64 or the default value while it's present and input is blank.

func (*Context) GetUint8

func (ctx *Context) GetUint8(key string, def ...uint8) (uint8, error)

GetUint8 return input as an uint8 or the default value while it's present and input is blank

func (Context) HTML

func (res Context) HTML(html string) error

HTML writes html text to.Body.

func (Context) HTMLBlob

func (res Context) HTMLBlob(data []byte) error

HTMLBlob writes html text to.Body from []byte.

func (Context) Header

func (req Context) Header(key string) string

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

func (ctx *Context) Input() url.Values

Input Request returns the input data map from POST or PUT request body and query string.

func (Context) Is

func (req Context) Is(method string) bool

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

func (*Context) IsAjax

func (ctx *Context) IsAjax() bool

IsAjax returns this request is ajax or not.

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

func (req Context) IsGet() bool

IsGet Is this a GET method request?

func (Context) IsHead

func (req Context) IsHead() bool

IsHead Is this a Head method request?

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

func (req Context) IsPatch() bool

IsPatch Is this a PATCH method request?

func (Context) IsPost

func (req Context) IsPost() bool

IsPost Is this a POST method request?

func (Context) IsPut

func (req Context) IsPut() bool

IsPut Is this a PUT 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

func (res Context) JSON(data interface{}, hasIndent bool, encoding bool) error

JSON writes json to.Bodyres. if encoding is true, it converts utf-8 to \u0000 type.

func (Context) JSONP

func (res Context) JSONP(data interface{}, hasIndent bool) error

JSONP writes jsonp to.Body.

func (Context) MSGPack added in v1.13.0

func (res Context) MSGPack(data interface{}) error

MSGPack writes protobuf to.Body.

func (Context) Method

func (req Context) Method() string

Method returns http request method.

func (Context) NoContent

func (res Context) NoContent() error

NoContent white res

func (Context) Param

func (req Context) Param(key string) string

Param returns router param by a given key.

func (Context) Params

func (req Context) Params() map[string]string

Params returns the map[key]value.

func (Context) ParamsLen

func (req Context) ParamsLen() int

ParamsLen return the length of the params

func (Context) ParseFormOrMultiForm

func (req Context) ParseFormOrMultiForm(maxMemory int64) error

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

func (req Context) Proxy() []string

Proxy returns proxy client ips slice.

func (Context) PutData

func (res Context) PutData(key interface{}, data interface{}) Response

PutData set the data depending on the accepted

func (Context) Query

func (req Context) Query(key string) string

Query returns input data item string by a given string.

func (Context) Redirect

func (res Context) Redirect(url string) error

Redirect header location redirect

func (Context) Refer

func (req Context) Refer() string

Refer returns http referer header.

func (Context) Referer

func (req Context) Referer() string

Referer returns http referer header.

func (Context) RenderMethodResult

func (res Context) RenderMethodResult(result interface{}) Response

RenderMethodResult renders the return value of a controller method to the output

func (*Context) Request

func (ctx *Context) Request() Request

Request get actions for requests

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

func (ctx *Context) Response() Response

Response get actions for response

func (*Context) SaveToFile

func (ctx *Context) SaveToFile(fromFile, toFile string) error

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

func (res Context) ServeFormatted(encoding ...bool) error

ServeFormatted serve YAML, XML, JSON, ProtoBuffer, Html or Text, depending on the value of the Accept header

func (Context) ServeHTML

func (res Context) ServeHTML() error

ServeHTML sends html response.

func (Context) ServeJSON

func (res Context) ServeJSON(encoding ...bool) error

ServeJSON sends a json response with encoding charset.

func (Context) ServeJSONP

func (res Context) ServeJSONP() error

ServeJSONP sends a jsonp response.

func (Context) ServeMSGPack added in v1.13.0

func (res Context) ServeMSGPack() error

ServeMSGPack sends msgpack 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) ServeXML

func (res Context) ServeXML() error

ServeXML sends xml response.

func (Context) ServeYAML

func (res Context) ServeYAML() error

ServeYAML sends yaml 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 SetFlash set the data depending on the accepted

func (Context) SetCookie

func (res Context) SetCookie(name string, value string, others ...interface{}) Response

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

func (res Context) SetHeader(key, val string) Response

Header sets.Header item string via given key.

func (Context) SetParam

func (req Context) SetParam(key, val string)

SetParam will set the param with key and value

func (Context) SetSecureCookie

func (res Context) SetSecureCookie(Secret, name, value string, others ...interface{}) Response

SetSecureCookie Set Secure cookie for response.

func (*Context) SetSession

func (ctx *Context) SetSession(name interface{}, value interface{}) *Context

SetSession puts value into session.

func (Context) SetStatus

func (res Context) SetStatus(status int) Response

Setstatus sets res status code. It writes.Header directly.

func (Context) SetXSRFToken

func (res Context) SetXSRFToken(key string, expire int64) string

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

func (res Context) Stream(contentType string, r io.Reader) (err error)

Stream writes stream to.Body.

func (Context) SubDomains

func (req Context) SubDomains() string

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

func (Context) Text

func (res Context) Text(data string) error

Text writes plain text to.Body.

func (Context) TextBlob

func (res Context) TextBlob(data []byte) (err error)

TextBlob writes plain text to.Body from []byte.

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

func (res Context) XML(data interface{}, hasIndent bool) error

XML writes xml string to.Body.

func (*Context) XSRFFormHTML

func (ctx *Context) XSRFFormHTML() string

XSRFFormHTML writes an input field contains xsrf token value.

func (Context) XSRFToken

func (res Context) XSRFToken() string

XSRFToken get _xsrfToken value

func (Context) YAML

func (res Context) YAML(data interface{}) error

YAML writes yaml to.Body.

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
	AcceptsMSGPack() bool
	AcceptsTextPlain() 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
	MSGPack(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

type ResponseWriter struct {
	http.ResponseWriter
	Started bool
	Status  int
	Elapsed time.Duration
}

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

func (r *ResponseWriter) Flush()

Flush http.Flusher

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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