Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertMapToStruct(tagName string, ptr interface{}, form map[string][]string) error
- type HostEnvironment
- type HttpContext
- func (c *HttpContext) AsciiJSON(code int, obj interface{})
- func (ctx *HttpContext) Bind(i interface{}) (err error)
- func (ctx *HttpContext) Error(code int, error string)
- func (c *HttpContext) File(filepath string)
- func (c *HttpContext) FileStream(code int, bytes []byte)
- func (ctx *HttpContext) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (ctx *HttpContext) FullRemoteIP() string
- func (ctx *HttpContext) GetAllParam() url.Values
- func (ctx *HttpContext) GetCookie(name string) string
- func (ctx *HttpContext) GetItem(key string) interface{}
- func (ctx *HttpContext) GetStatus() int
- func (ctx *HttpContext) HTML(code int, name string, obj interface{})
- func (c *HttpContext) Header(key, value string)
- func (ctx *HttpContext) IndentedJSON(code int, obj interface{})
- func (ctx *HttpContext) IsAJAX() bool
- func (ctx *HttpContext) IsWebsocket() bool
- func (c *HttpContext) JSON(code int, obj interface{})
- func (c *HttpContext) JSONP(code int, obj interface{})
- func (ctx *HttpContext) Method() string
- func (ctx *HttpContext) Param(name string) string
- func (ctx *HttpContext) Path() string
- func (ctx *HttpContext) PostBody() []byte
- func (ctx *HttpContext) PostForm() url.Values
- func (ctx *HttpContext) PostJsonForm() url.Values
- func (ctx *HttpContext) PostMultipartForm() url.Values
- func (c *HttpContext) ProtoBuf(code int, obj interface{})
- func (c *HttpContext) PureJSON(code int, obj interface{})
- func (ctx *HttpContext) Query(key string) string
- func (ctx *HttpContext) QueryStringOrDefault(key string, defaultval string) string
- func (ctx *HttpContext) QueryStrings() url.Values
- func (ctx *HttpContext) RealIP() string
- func (ctx *HttpContext) Redirect(code int, url string)
- func (ctx *HttpContext) Referer() string
- func (ctx *HttpContext) RemoteIP() string
- func (c *HttpContext) Render(code int, r ActionResult.IActionResult)
- func (ctx *HttpContext) SaveFile(name, saveDir string) (string, error)
- func (c *HttpContext) SecureJSON(code int, obj interface{})
- func (ctx *HttpContext) SetCookie(name, value string)
- func (ctx *HttpContext) SetItem(key string, val interface{})
- func (ctx *HttpContext) Status(code int)
- func (c *HttpContext) Text(code int, format string, values ...interface{})
- func (ctx *HttpContext) Url() string
- func (ctx *HttpContext) UserAgent() string
- func (ctx *HttpContext) Write(data []byte) (n int, err error)
- func (c *HttpContext) XML(code int, obj interface{})
- func (c *HttpContext) YAML(code int, obj interface{})
- type M
- type ResponseWriter
Constants ¶
const ( Dev = "Dev" Prod = "Prod" Test = "Test" )
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + CharsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + CharsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationYAML = "application/x-yaml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + CharsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + CharsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + CharsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
const ( HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-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" HeaderXRequestedWith = "X-Requested-With" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" HeaderServer = "Server" HeaderOrigin = "Origin" 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" HeaderP3P = "P3P" HeaderCacheControl = "Cache-control" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderXCSRFToken = "X-CSRF-Token" )
Headers
const ( CONNECT = http.MethodConnect DELETE = http.MethodDelete GET = http.MethodGet HEAD = http.MethodHead OPTIONS = http.MethodOptions PATCH = http.MethodPatch POST = http.MethodPost PUT = http.MethodPut TRACE = http.MethodTrace )
const (
CharsetUTF8 = "charset=utf-8"
)
Http define
Variables ¶
var Methods = [...]string{ http.MethodConnect, http.MethodDelete, http.MethodGet, http.MethodHead, http.MethodOptions, http.MethodPatch, http.MethodPost, http.MethodPut, http.MethodTrace, }
Functions ¶
Types ¶
type HostEnvironment ¶ added in v1.4.0
type HostEnvironment struct { ApplicationName string Version string Profile string Args []string Addr string Port string PID int }
func (HostEnvironment) IsDevelopment ¶ added in v1.4.0
func (env HostEnvironment) IsDevelopment() bool
func (HostEnvironment) IsProduction ¶ added in v1.4.0
func (env HostEnvironment) IsProduction() bool
func (HostEnvironment) IsStaging ¶ added in v1.4.0
func (env HostEnvironment) IsStaging() bool
type HttpContext ¶
type HttpContext struct { Request *http.Request Response *responseWriter RouterData url.Values RequiredServices DependencyInjection.IServiceProvider Result interface{} // contains filtered or unexported fields }
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request, sp DependencyInjection.IServiceProvider) *HttpContext
func (*HttpContext) AsciiJSON ¶
func (c *HttpContext) AsciiJSON(code int, obj interface{})
AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string. It also sets the Content-Type as "application/json".
func (*HttpContext) Bind ¶
func (ctx *HttpContext) Bind(i interface{}) (err error)
func (*HttpContext) Error ¶
func (ctx *HttpContext) Error(code int, error string)
Write Error Response.
func (*HttpContext) File ¶
func (c *HttpContext) File(filepath string)
func (*HttpContext) FileStream ¶
func (c *HttpContext) FileStream(code int, bytes []byte)
func (*HttpContext) FormFile ¶
func (ctx *HttpContext) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
FormFile gets file from request.
func (*HttpContext) FullRemoteIP ¶
func (ctx *HttpContext) FullRemoteIP() string
FullRemoteIP RemoteAddr to an "IP:port" address
func (*HttpContext) GetAllParam ¶
func (ctx *HttpContext) GetAllParam() url.Values
func (*HttpContext) GetCookie ¶
func (ctx *HttpContext) GetCookie(name string) string
Get Cookie by Name
func (*HttpContext) GetItem ¶
func (ctx *HttpContext) GetItem(key string) interface{}
Get data in context.
func (*HttpContext) HTML ¶
func (ctx *HttpContext) HTML(code int, name string, obj interface{})
func (*HttpContext) Header ¶
func (c *HttpContext) Header(key, value string)
func (*HttpContext) IndentedJSON ¶
func (ctx *HttpContext) IndentedJSON(code int, obj interface{})
func (*HttpContext) IsAJAX ¶
func (ctx *HttpContext) IsAJAX() bool
IsAJAX returns if it is a ajax request
func (*HttpContext) IsWebsocket ¶
func (ctx *HttpContext) IsWebsocket() bool
func (*HttpContext) JSON ¶
func (c *HttpContext) JSON(code int, obj interface{})
func (*HttpContext) JSONP ¶
func (c *HttpContext) JSONP(code int, obj interface{})
func (*HttpContext) PostBody ¶
func (ctx *HttpContext) PostBody() []byte
PostBody returns data from the POST or PUT request body
func (*HttpContext) PostJsonForm ¶
func (ctx *HttpContext) PostJsonForm() url.Values
func (*HttpContext) PostMultipartForm ¶
func (ctx *HttpContext) PostMultipartForm() url.Values
func (*HttpContext) ProtoBuf ¶
func (c *HttpContext) ProtoBuf(code int, obj interface{})
ProtoBuf serializes the given struct as ProtoBuf into the response body.
func (*HttpContext) PureJSON ¶
func (c *HttpContext) PureJSON(code int, obj interface{})
PureJSON serializes the given struct as JSON into the response body. PureJSON, unlike JSON, does not replace special html characters with their unicode entities.
func (*HttpContext) Query ¶
func (ctx *HttpContext) Query(key string) string
Get Query String By Key GET /path?id=1234&name=Manu&value= c.Query("id") == "1234" c.Query("name") == "Manu" c.Query("value") == "" c.Query("wtf") == ""
func (*HttpContext) QueryStringOrDefault ¶
func (ctx *HttpContext) QueryStringOrDefault(key string, defaultval string) string
func (*HttpContext) QueryStrings ¶
func (ctx *HttpContext) QueryStrings() url.Values
Get Query string
func (*HttpContext) RealIP ¶
func (ctx *HttpContext) RealIP() string
RealIP returns the first ip from 'X-Forwarded-For' or 'X-Real-IP' header key if not exists data, returns request.RemoteAddr fixed for #164
func (*HttpContext) Redirect ¶
func (ctx *HttpContext) Redirect(code int, url string)
Redirect redirects the request
func (*HttpContext) Referer ¶
func (ctx *HttpContext) Referer() string
Referer returns request referer.
func (*HttpContext) RemoteIP ¶
func (ctx *HttpContext) RemoteIP() string
RemoteIP RemoteAddr to an "IP" address
func (*HttpContext) Render ¶
func (c *HttpContext) Render(code int, r ActionResult.IActionResult)
ActionResult writes the response headers and calls render.ActionResult to render data.
func (*HttpContext) SaveFile ¶
func (ctx *HttpContext) SaveFile(name, saveDir string) (string, error)
SaveFile saves the form file and returns the filename.
func (*HttpContext) SecureJSON ¶
func (c *HttpContext) SecureJSON(code int, obj interface{})
func (*HttpContext) SetCookie ¶
func (ctx *HttpContext) SetCookie(name, value string)
Set Cookie value
func (*HttpContext) SetItem ¶
func (ctx *HttpContext) SetItem(key string, val interface{})
Set data in context.
func (*HttpContext) Status ¶
func (ctx *HttpContext) Status(code int)
Status sets the HTTP response code.
func (*HttpContext) Text ¶
func (c *HttpContext) Text(code int, format string, values ...interface{})
String writes the given string into the response body.
func (*HttpContext) UserAgent ¶
func (ctx *HttpContext) UserAgent() string
UserAgent returns http request UserAgent
func (*HttpContext) Write ¶
func (ctx *HttpContext) Write(data []byte) (n int, err error)
Write Byte[] Response.
func (*HttpContext) XML ¶
func (c *HttpContext) XML(code int, obj interface{})
XML serializes the given struct as XML into the response body. It also sets the Content-Type as "application/xml".
func (*HttpContext) YAML ¶
func (c *HttpContext) YAML(code int, obj interface{})
YAML serializes the given struct as YAML into the response body.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher // Status returns the status code of the response or 0 if the response has // not been written Status() int // Written returns whether or not the ResponseWriter has been written. Written() bool // Size returns the size of the response body. Size() int // Before allows for a function to be called before the ResponseWriter has been written to. This is // useful for setting headers or any other operations that must happen before a response has been written. Before(func(ResponseWriter)) }
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter