Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertMapToStruct(tagName string, ptr interface{}, form map[string][]string) error
- type CResponseWriter
- func (rw *CResponseWriter) Before(before func(IResponseWriter))
- func (rw *CResponseWriter) Flush()
- func (rw *CResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (rw *CResponseWriter) SetStatus(code int)
- func (rw *CResponseWriter) Size() int
- func (rw *CResponseWriter) Status() int
- func (rw *CResponseWriter) Write(b []byte) (int, error)
- func (rw *CResponseWriter) WriteHeader(s int)
- func (w *CResponseWriter) WriteHeaderNow()
- func (rw *CResponseWriter) Written() bool
- type H
- type HttpContext
- func (ctx *HttpContext) AsciiJSON(code int, obj interface{})
- func (ctx *HttpContext) Bind(i interface{}) (err error)
- func (ctx *HttpContext) File(filepath string)
- func (ctx *HttpContext) FileStream(code int, bytes []byte)
- func (ctx *HttpContext) GetItem(key string) interface{}
- func (ctx *HttpContext) GetSession() *Session
- func (ctx *HttpContext) GetUser() map[string]interface{}
- func (ctx *HttpContext) HTML(code int, name string, obj interface{})
- func (ctx *HttpContext) IndentedJSON(code int, obj interface{})
- func (ctx *HttpContext) JSON(code int, obj interface{})
- func (ctx *HttpContext) JSONP(code int, obj interface{})
- func (ctx *HttpContext) ProtoBuf(code int, obj interface{})
- func (ctx *HttpContext) PureJSON(code int, obj interface{})
- func (ctx *HttpContext) Redirect(code int, url string)
- func (ctx *HttpContext) Render(code int, r actionresult.IActionResult)
- func (ctx *HttpContext) SecureJSON(code int, obj interface{})
- func (ctx *HttpContext) SetItem(key string, val interface{})
- func (ctx *HttpContext) Text(code int, format string, values ...interface{})
- func (ctx *HttpContext) XML(code int, obj interface{})
- func (ctx *HttpContext) YAML(code int, obj interface{})
- type IResponseWriter
- type ISessionManager
- type Input
- func (input Input) Domain() string
- func (input Input) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (input Input) FullRemoteIP() string
- func (input Input) GetAllParam() url.Values
- func (input Input) GetCookie(name string) string
- func (input Input) GetReader() *http.Request
- func (input Input) Header(key string) string
- func (input Input) Host() string
- func (input Input) IsAJAX() bool
- func (input Input) IsUpload() bool
- func (input Input) IsWebsocket() bool
- func (input Input) Method() string
- func (input Input) Param(name string) string
- func (input Input) ParseFormOrMultipartForm(maxMemory int64) error
- func (input Input) Path() string
- func (input Input) Query(key string) string
- func (input Input) QueryDefault(key string, defaultval string) string
- func (input Input) QueryStrings() url.Values
- func (input Input) RealIP() string
- func (input Input) Referer() string
- func (input Input) RemoteIP() string
- func (input Input) Reset(request *http.Request)
- func (input Input) SaveFile(name, saveDir string) (string, error)
- func (input Input) Scheme() string
- func (input Input) Url() string
- func (input Input) UserAgent() string
- type Output
- func (output Output) Error(code int, error string)
- func (output Output) GetWriter() IResponseWriter
- func (output Output) Header(key, value string)
- func (output Output) SetCookie(name, value string)
- func (output Output) SetStatus(status int)
- func (output Output) SetStatusCode(status int)
- func (output Output) SetStatusCodeNow()
- func (output Output) Status() int
- func (output Output) Write(data []byte) (n int, err error)
- type Session
- func (session Session) GetFloat(key string) float32
- func (session Session) GetFloat64(key string) float64
- func (session Session) GetInt(key string) int
- func (session Session) GetInt64(key string) int64
- func (session Session) GetString(key string) string
- func (session Session) GetValue(key string) (interface{}, bool)
- func (session Session) SetValue(key string, value interface{})
Constants ¶
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 CResponseWriter ¶
type CResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func (*CResponseWriter) Before ¶
func (rw *CResponseWriter) Before(before func(IResponseWriter))
func (*CResponseWriter) Flush ¶
func (rw *CResponseWriter) Flush()
func (*CResponseWriter) Hijack ¶
func (rw *CResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*CResponseWriter) SetStatus ¶
func (rw *CResponseWriter) SetStatus(code int)
func (*CResponseWriter) Size ¶
func (rw *CResponseWriter) Size() int
func (*CResponseWriter) Status ¶
func (rw *CResponseWriter) Status() int
func (*CResponseWriter) WriteHeader ¶
func (rw *CResponseWriter) WriteHeader(s int)
func (*CResponseWriter) WriteHeaderNow ¶
func (w *CResponseWriter) WriteHeaderNow()
func (*CResponseWriter) Written ¶
func (rw *CResponseWriter) Written() bool
type HttpContext ¶
type HttpContext struct { Input Input Output Output 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 (ctx *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) File ¶
func (ctx *HttpContext) File(filepath string)
func (*HttpContext) FileStream ¶
func (ctx *HttpContext) FileStream(code int, bytes []byte)
func (*HttpContext) GetItem ¶
func (ctx *HttpContext) GetItem(key string) interface{}
Get data in context.
func (*HttpContext) GetSession ¶ added in v1.6.2
func (ctx *HttpContext) GetSession() *Session
func (*HttpContext) GetUser ¶
func (ctx *HttpContext) GetUser() map[string]interface{}
Get JWT UserInfo
func (*HttpContext) HTML ¶
func (ctx *HttpContext) HTML(code int, name string, obj interface{})
func (*HttpContext) IndentedJSON ¶
func (ctx *HttpContext) IndentedJSON(code int, obj interface{})
func (*HttpContext) JSON ¶
func (ctx *HttpContext) JSON(code int, obj interface{})
func (*HttpContext) JSONP ¶
func (ctx *HttpContext) JSONP(code int, obj interface{})
func (*HttpContext) ProtoBuf ¶
func (ctx *HttpContext) ProtoBuf(code int, obj interface{})
ProtoBuf serializes the given struct as ProtoBuf into the response body.
func (*HttpContext) PureJSON ¶
func (ctx *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) Redirect ¶
func (ctx *HttpContext) Redirect(code int, url string)
Redirect redirects the request
func (*HttpContext) Render ¶
func (ctx *HttpContext) Render(code int, r actionresult.IActionResult)
actionresult writes the response headers and calls render.actionresult to render data.
func (*HttpContext) SecureJSON ¶
func (ctx *HttpContext) SecureJSON(code int, obj interface{})
func (*HttpContext) SetItem ¶
func (ctx *HttpContext) SetItem(key string, val interface{})
Set data in context.
func (*HttpContext) Text ¶
func (ctx *HttpContext) Text(code int, format string, values ...interface{})
String writes the given string into the response body.
func (*HttpContext) XML ¶
func (ctx *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 (ctx *HttpContext) YAML(code int, obj interface{})
YAML serializes the given struct as YAML into the response body.
type IResponseWriter ¶
type IResponseWriter 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 IResponseWriter 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 IResponseWriter 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(IResponseWriter)) }
IResponseWriter 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) IResponseWriter
NewResponseWriter creates a IResponseWriter that wraps an http.ResponseWriter
type ISessionManager ¶ added in v1.6.2
type ISessionManager interface { GetIDList() []string Clear(interface{}) Load(interface{}) string NewSession(sessionId string) string Remove(sessionId string) SetValue(sessionID string, key string, value interface{}) GetValue(sessionID string, key string) (interface{}, bool) GC() }
ISessionManager session manager of interface
type Input ¶
type Input struct { Request *http.Request FormBody []byte RouterData url.Values // contains filtered or unexported fields }
func (Input) FullRemoteIP ¶
FullRemoteIP RemoteAddr to an "IP:port" address
func (Input) GetAllParam ¶
func (Input) Header ¶
Header returns request header item string by a given string. if non-existed, return empty string.
func (Input) IsWebsocket ¶
func (Input) ParseFormOrMultipartForm ¶
ParseFormOrMultipartForm parseForm or parseMultiForm based on Content-type
func (Input) Query ¶
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 (Input) RealIP ¶
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
type Output ¶
type Output struct {
Response IResponseWriter
}
func (Output) GetWriter ¶
func (output Output) GetWriter() IResponseWriter
func (Output) SetStatusCode ¶
func (Output) SetStatusCodeNow ¶
func (output Output) SetStatusCodeNow()
type Session ¶ added in v1.6.2
type Session struct {
// contains filtered or unexported fields
}
Session current session by http context
func NewSession ¶ added in v1.6.2
func NewSession(sessionId string, mgr ISessionManager) *Session