Documentation
¶
Index ¶
- Constants
- Variables
- func Dump(v ...interface{})
- func Exists(path string) bool
- func LoadConfigFile(file string) config
- func MIME(extension string) (mime string)
- func MakePath(name, dst string, args ...interface{}) (string, string, error)
- func NewTree() *tree
- func Panicf(s string, args ...interface{})
- func SaveConfigFile(conf map[string]interface{}) error
- func StatusMessage(status int) string
- type Core
- func (c *Core) AddHandle(methods interface{}, path string, handler interface{}) error
- func (c *Core) Connect(path string, handler interface{}) error
- func (c *Core) Delete(path string, handler interface{}) error
- func (c *Core) Get(path string, handler interface{}) error
- func (c *Core) Head(path string, handler interface{}) error
- func (c *Core) ListenAndServe(addr ...string) error
- func (c *Core) Options(path string, handler interface{}) error
- func (c *Core) Patch(path string, handler interface{}) error
- func (c *Core) Post(path string, handler interface{}) error
- func (c *Core) Put(path string, handler interface{}) error
- func (c *Core) Serve(ln net.Listener) error
- func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Core) SetFuncMap(funcMap template.FuncMap) *Core
- func (c *Core) Static(path, dirname string) error
- func (c *Core) Trace(path string, handler interface{}) error
- func (c *Core) Use(args ...interface{}) *Core
- type Ctx
- func (c *Ctx) Abort(args ...interface{})
- func (c *Ctx) Cookie(name string) (string, error)
- func (c *Ctx) Core() *Core
- func (c *Ctx) File(filepath string)
- func (c *Ctx) FileAttachment(filepath, filename string)
- func (c *Ctx) FileFromFS(filepath string, fs http.FileSystem)
- func (c *Ctx) Final() *Ctx
- func (c *Ctx) FinalJSON(data interface{}) error
- func (c *Ctx) FinalToJSON(data interface{}, err error) error
- func (c *Ctx) Flush(data interface{}, statusCode ...int) error
- func (c *Ctx) FormFile(key string) (*multipart.FileHeader, error)
- func (c *Ctx) FormValue(key string, def ...string) string
- func (c *Ctx) FromValues(key string, def ...[]string) []string
- func (c *Ctx) Get(key string) (val interface{}, ok bool)
- func (c *Ctx) GetAs(key string, v interface{}) error
- func (c *Ctx) GetBool(key string) (value bool)
- func (c *Ctx) GetDuration(key string) (d time.Duration)
- func (c *Ctx) GetFloat64(key string, def ...float64) (value float64)
- func (c *Ctx) GetHeader(key string) string
- func (c *Ctx) GetInt(key string, def ...int) (i int)
- func (c *Ctx) GetInt64(key string, def ...int64) (i int64)
- func (c *Ctx) GetMap(key string, def ...map[string]interface{}) (value map[string]interface{})
- func (c *Ctx) GetMapString(key string, def ...map[string]string) (value map[string]string)
- func (c *Ctx) GetMapStringSlice(key string, def ...map[string][]string) (value map[string][]string)
- func (c *Ctx) GetParam(k string, def ...string) string
- func (c *Ctx) GetStatus() int
- func (c *Ctx) GetString(key string, def ...string) (value string)
- func (c *Ctx) GetStrings(key string, def ...[]string) (value []string)
- func (c *Ctx) GetTime(key string) (t time.Time)
- func (c *Ctx) GetUint(key string, def ...uint) (i uint)
- func (c *Ctx) GetUint64(key string, def ...uint64) (i uint64)
- func (c *Ctx) JSON(data interface{}) error
- func (c *Ctx) JSONP(data interface{}, callback ...string) error
- func (c *Ctx) Next()
- func (c *Ctx) Params() params
- func (c *Ctx) ReadBody(out interface{}) error
- func (c *Ctx) RemoteIP() (net.IP, bool)
- func (c *Ctx) SaveFile(key, dst string, args ...interface{}) (relpath, abspath string, err error)
- func (c *Ctx) Send(buf []byte) error
- func (c *Ctx) SendStatus(status int, msg ...string) error
- func (c *Ctx) SendString(str ...interface{}) error
- func (c *Ctx) Set(key string, val interface{})
- func (c *Ctx) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (c *Ctx) SetHeader(key, value string)
- func (c *Ctx) SetParam(k, v string)
- func (c *Ctx) Status(status int) *Ctx
- func (c *Ctx) Stream(step func(w io.Writer) bool) bool
- func (c *Ctx) ToJSON(data interface{}, err error) error
- type ErrType
- type Error
- type Handler
- type HandlerFunc
- type HandlerFuncs
- type InmemoryListener
- type InvalidUnmarshalError
- type PipeConns
- type ResponseWriter
Constants ¶
const ( StatusContinue = 100 // RFC 7231, 6.2.1 StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 StatusProcessing = 102 // RFC 2518, 10.1 StatusEarlyHints = 103 // RFC 8297 StatusOK = 200 // RFC 7231, 6.3.1 StatusCreated = 201 // RFC 7231, 6.3.2 StatusAccepted = 202 // RFC 7231, 6.3.3 StatusNonAuthoritativeInformation = 203 // RFC 7231, 6.3.4 StatusNoContent = 204 // RFC 7231, 6.3.5 StatusResetContent = 205 // RFC 7231, 6.3.6 StatusPartialContent = 206 // RFC 7233, 4.1 StatusMultiStatus = 207 // RFC 4918, 11.1 StatusAlreadyReported = 208 // RFC 5842, 7.1 StatusIMUsed = 226 // RFC 3229, 10.4.1 StatusMultipleChoices = 300 // RFC 7231, 6.4.1 StatusMovedPermanently = 301 // RFC 7231, 6.4.2 StatusFound = 302 // RFC 7231, 6.4.3 StatusSeeOther = 303 // RFC 7231, 6.4.4 StatusNotModified = 304 // RFC 7232, 4.1 StatusUseProxy = 305 // RFC 7231, 6.4.5 StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 StatusPermanentRedirect = 308 // RFC 7538, 3 StatusBadRequest = 400 // RFC 7231, 6.5.1 StatusPaymentRequired = 402 // RFC 7231, 6.5.2 StatusForbidden = 403 // RFC 7231, 6.5.3 StatusNotFound = 404 // RFC 7231, 6.5.4 StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5 StatusNotAcceptable = 406 // RFC 7231, 6.5.6 StatusProxyAuthRequired = 407 // RFC 7235, 3.2 StatusRequestTimeout = 408 // RFC 7231, 6.5.7 StatusConflict = 409 // RFC 7231, 6.5.8 StatusGone = 410 // RFC 7231, 6.5.9 StatusLengthRequired = 411 // RFC 7231, 6.5.10 StatusPreconditionFailed = 412 // RFC 7232, 4.2 StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11 StatusRequestURITooLong = 414 // RFC 7231, 6.5.12 StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13 StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4 StatusExpectationFailed = 417 // RFC 7231, 6.5.14 StatusTeapot = 418 // RFC 7168, 2.3.3 StatusMisdirectedRequest = 421 // RFC 7540, 9.1.2 StatusUnprocessableEntity = 422 // RFC 4918, 11.2 StatusLocked = 423 // RFC 4918, 11.3 StatusFailedDependency = 424 // RFC 4918, 11.4 StatusTooEarly = 425 // RFC 8470, 5.2. StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 StatusPreconditionRequired = 428 // RFC 6585, 3 StatusTooManyRequests = 429 // RFC 6585, 4 StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 StatusInternalServerError = 500 // RFC 7231, 6.6.1 StatusNotImplemented = 501 // RFC 7231, 6.6.2 StatusBadGateway = 502 // RFC 7231, 6.6.3 StatusGatewayTimeout = 504 // RFC 7231, 6.6.5 StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6 StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1 StatusInsufficientStorage = 507 // RFC 4918, 11.5 StatusLoopDetected = 508 // RFC 5842, 7.2 StatusNotExtended = 510 // RFC 2774, 7 StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6 )
HTTP status codes were copied from net/http.
const ( HeaderAuthorization = "Authorization" HeaderProxyAuthenticate = "Proxy-Authenticate" HeaderProxyAuthorization = "Proxy-Authorization" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderAge = "Age" HeaderCacheControl = "Cache-Control" HeaderClearSiteData = "Clear-Site-Data" HeaderExpires = "Expires" HeaderPragma = "Pragma" HeaderWarning = "Warning" HeaderAcceptCH = "Accept-CH" HeaderAcceptCHLifetime = "Accept-CH-Lifetime" HeaderContentDPR = "Content-DPR" HeaderDPR = "DPR" HeaderEarlyData = "Early-Data" HeaderSaveData = "Save-Data" HeaderViewportWidth = "Viewport-Width" HeaderWidth = "Width" HeaderETag = "ETag" HeaderIfMatch = "If-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderLastModified = "Last-Modified" HeaderVary = "Vary" HeaderConnection = "Connection" HeaderKeepAlive = "Keep-Alive" HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" HeaderCookie = "Cookie" HeaderExpect = "Expect" HeaderMaxForwards = "Max-Forwards" HeaderSetCookie = "Set-Cookie" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderOrigin = "Origin" HeaderTimingAllowOrigin = "Timing-Allow-Origin" HeaderXPermittedCrossDomainPolicies = "X-Permitted-Cross-Domain-Policies" HeaderDNT = "DNT" HeaderTk = "Tk" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLanguage = "Content-Language" HeaderContentLength = "Content-Length" HeaderContentLocation = "Content-Location" HeaderContentType = "Content-Type" HeaderForwarded = "Forwarded" HeaderVia = "Via" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedHost = "X-Forwarded-Host" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderLocation = "Location" HeaderFrom = "From" HeaderHost = "Host" HeaderReferer = "Referer" HeaderReferrerPolicy = "Referrer-Policy" HeaderUserAgent = "User-Agent" HeaderAllow = "Allow" HeaderServer = "Server" HeaderAcceptRanges = "Accept-Ranges" HeaderContentRange = "Content-Range" HeaderIfRange = "If-Range" HeaderRange = "Range" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy" HeaderExpectCT = "Expect-CT" HeaderFeaturePolicy = "Feature-Policy" HeaderPublicKeyPins = "Public-Key-Pins" HeaderPublicKeyPinsReportOnly = "Public-Key-Pins-Report-Only" HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderUpgradeInsecureRequests = "Upgrade-Insecure-Requests" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXDownloadOptions = "X-Download-Options" HeaderXFrameOptions = "X-Frame-Options" HeaderXPoweredBy = "X-Powered-By" HeaderXXSSProtection = "X-XSS-Protection" HeaderLastEventID = "Last-Event-ID" HeaderNEL = "NEL" HeaderPingFrom = "Ping-From" HeaderPingTo = "Ping-To" HeaderReportTo = "Report-To" HeaderTE = "TE" HeaderTrailer = "Trailer" HeaderTransferEncoding = "Transfer-Encoding" HeaderSecWebSocketAccept = "Sec-WebSocket-Accept" HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" HeaderSecWebSocketKey = "Sec-WebSocket-Key" HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol" HeaderSecWebSocketVersion = "Sec-WebSocket-Version" HeaderAcceptPatch = "Accept-Patch" HeaderAcceptPushPolicy = "Accept-Push-Policy" HeaderAcceptSignature = "Accept-Signature" HeaderAltSvc = "Alt-Svc" HeaderDate = "Date" HeaderIndex = "Index" HeaderLargeAllocation = "Large-Allocation" HeaderLink = "Link" HeaderPushPolicy = "Push-Policy" HeaderRetryAfter = "Retry-After" HeaderServerTiming = "Server-Timing" HeaderSignature = "Signature" HeaderSignedHeaders = "Signed-Headers" HeaderSourceMap = "SourceMap" HeaderUpgrade = "Upgrade" HeaderXDNSPrefetchControl = "X-DNS-Prefetch-Control" HeaderXPingback = "X-Pingback" HeaderXRequestID = "X-Request-ID" HeaderXRequestedWith = "X-Requested-With" HeaderXRobotsTag = "X-Robots-Tag" HeaderXUACompatible = "X-UA-Compatible" )
HTTP Headers were copied from net/http.
const ( MIMETextXML = "text/xml" MIMETextHTML = "text/html" MIMETextPlain = "text/plain" MIMEApplicationXML = "application/xml" MIMEApplicationJSON = "application/json" MIMEApplicationJavaScript = "application/javascript" MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEOctetStream = "application/octet-stream" MIMEMultipartForm = "multipart/form-data" MIMETextXMLCharsetUTF8 = "text/xml; charset=utf-8" MIMETextHTMLCharsetUTF8 = "text/html; charset=utf-8" MIMETextPlainCharsetUTF8 = "text/plain; charset=utf-8" MIMEApplicationXMLCharsetUTF8 = "application/xml; charset=utf-8" MIMEApplicationJSONCharsetUTF8 = "application/json; charset=utf-8" MIMEApplicationJavaScriptCharsetUTF8 = "application/javascript; charset=utf-8" )
MIME types that are commonly used
const ( MethodUse = "USE" MethodConnect = "CONNECT" // RFC 7231, 4.3.6 MethodDelete = "DELETE" // RFC 7231, 4.3.5 MethodGet = "GET" // RFC 7231, 4.3.1 MethodHead = "HEAD" // RFC 7231, 4.3.2 MethodOptions = "OPTIONS" // RFC 7231, 4.3.7 MethodPatch = "PATCH" // RFC 5789 MethodPost = "POST" // RFC 7231, 4.3.3 MethodPut = "PUT" // RFC 7231, 4.3.4 MethodTrace = "TRACE" // RFC 7231, 4.3.8 )
HTTP methods were copied from net/http.
Variables ¶
var ( ErrBadRequest = NewError(StatusBadRequest) // RFC 7231, 6.5.1 ErrPaymentRequired = NewError(StatusPaymentRequired) // RFC 7231, 6.5.2 ErrForbidden = NewError(StatusForbidden) // RFC 7231, 6.5.3 ErrNotFound = NewError(StatusNotFound) // RFC 7231, 6.5.4 ErrMethodNotAllowed = NewError(StatusMethodNotAllowed) // RFC 7231, 6.5.5 ErrNotAcceptable = NewError(StatusNotAcceptable) // RFC 7231, 6.5.6 ErrProxyAuthRequired = NewError(StatusProxyAuthRequired) // RFC 7235, 3.2 ErrRequestTimeout = NewError(StatusRequestTimeout) // RFC 7231, 6.5.7 ErrConflict = NewError(StatusConflict) // RFC 7231, 6.5.8 ErrGone = NewError(StatusGone) // RFC 7231, 6.5.9 ErrLengthRequired = NewError(StatusLengthRequired) // RFC 7231, 6.5.10 ErrPreconditionFailed = NewError(StatusPreconditionFailed) // RFC 7232, 4.2 ErrRequestEntityTooLarge = NewError(StatusRequestEntityTooLarge) // RFC 7231, 6.5.11 ErrRequestURITooLong = NewError(StatusRequestURITooLong) // RFC 7231, 6.5.12 ErrUnsupportedMediaType = NewError(StatusUnsupportedMediaType) // RFC 7231, 6.5.13 ErrRequestedRangeNotSatisfiable = NewError(StatusRequestedRangeNotSatisfiable) // RFC 7233, 4.4 ErrExpectationFailed = NewError(StatusExpectationFailed) // RFC 7231, 6.5.14 ErrTeapot = NewError(StatusTeapot) // RFC 7168, 2.3.3 ErrMisdirectedRequest = NewError(StatusMisdirectedRequest) // RFC 7540, 9.1.2 ErrUnprocessableEntity = NewError(StatusUnprocessableEntity) // RFC 4918, 11.2 ErrLocked = NewError(StatusLocked) // RFC 4918, 11.3 ErrFailedDependency = NewError(StatusFailedDependency) // RFC 4918, 11.4 ErrTooEarly = NewError(StatusTooEarly) // RFC 8470, 5.2. ErrUpgradeRequired = NewError(StatusUpgradeRequired) // RFC 7231, 6.5.15 ErrPreconditionRequired = NewError(StatusPreconditionRequired) // RFC 6585, 3 ErrTooManyRequests = NewError(StatusTooManyRequests) // RFC 6585, 4 ErrRequestHeaderFieldsTooLarge = NewError(StatusRequestHeaderFieldsTooLarge) // RFC 6585, 5 ErrInternalServerError = NewError(StatusInternalServerError) // RFC 7231, 6.6.1 ErrNotImplemented = NewError(StatusNotImplemented) // RFC 7231, 6.6.2 ErrBadGateway = NewError(StatusBadGateway) // RFC 7231, 6.6.3 ErrGatewayTimeout = NewError(StatusGatewayTimeout) // RFC 7231, 6.6.5 ErrHTTPVersionNotSupported = NewError(StatusHTTPVersionNotSupported) // RFC 7231, 6.6.6 ErrVariantAlsoNegotiates = NewError(StatusVariantAlsoNegotiates) // RFC 2295, 8.1 ErrInsufficientStorage = NewError(StatusInsufficientStorage) // RFC 4918, 11.5 ErrLoopDetected = NewError(StatusLoopDetected) // RFC 5842, 7.2 ErrNotExtended = NewError(StatusNotExtended) // RFC 2774, 7 ErrNetworkAuthenticationRequired = NewError(StatusNetworkAuthenticationRequired) // RFC 6585, 6 )
Errors
var ( // Error for handle not support. ErrHandleNotSupport = errors.New("handle does not support. Must use core.Handle, http.HandlerFunc or http.Handler") ErrDataTypeNotSupport = errors.New("dataType does not support") )
var ErrInmemoryListenerClosed = errors.New("InmemoryListener is already closed: use of closed network connection")
ErrInmemoryListenerClosed indicates that the InmemoryListener is already closed.
var (
// ErrTimeout is returned from Read() or Write() on timeout.
ErrTimeout = &timeoutError{}
)
var Methods = []string{ MethodUse, MethodGet, MethodHead, MethodPost, MethodPut, MethodDelete, MethodConnect, MethodOptions, MethodTrace, MethodPatch, }
Methods methods slice
Functions ¶
func LoadConfigFile ¶
func LoadConfigFile(file string) config
func MakePath ¶
MakePath make dir
path = {root}/{dst}/{id}
@param
name string filename
dst string dst path
root string root path optional
id path optional type uid.UID, int, uint, int64,uint64
rename bool optional
return relPath, absPath
`
MakePath("favicon.png", "/images")
(string) relpath "/images/10/favicon.png"
(string) abspath "/images/10/favicon.png"
MakePath("favicon.png", "/images", "/static")
(string) relpath "/images/10/5hsbkthaadld/favicon.png"
(string) abspath "/static/images/10/5hsbkthaadld/favicon.png"
MakePath("favicon.png", "/images", "/static", uid.New())
(string) relpath "/images/10/5hsbkthaadld/5hsbkthaadld.png"
(string) abspath "/static/images/10/5hsbkthaadld/5hsbkthaadld.png"
👇filename 👇dst 👇root 👇id 👇rename
MakePath("favicon.png", "/images", "/static", uid.New(), true)
(string) relpath "/images/10/5hsbkthaadld/5hsbkthaadld.png"
(string) abspath "/static/images/10/5hsbkthaadld/5hsbkthaadld.png"
`
func SaveConfigFile ¶
func StatusMessage ¶
StatusMessage returns the correct message for the provided HTTP statuscode
Types ¶
type Core ¶
type Core struct {
Debug bool
Conf config
// Value of 'maxMemory' param that is given to http.Request's ParseMultipartForm
// method call.
MaxMultipartMemory int64
ViewFuncMap template.FuncMap
RemoteIPHeaders []string
// contains filtered or unexported fields
}
func (*Core) AddHandle ¶
AddHandle
methods string || []string
path string /foo
handler core.Handle || http.HandlerFunc || http.Handler
app.AddHandle("GET", "/foo", func(c*core.Ctx){
c.SendString("hello world")
})
func (*Core) Get ¶
Get add get method
path string /foo
handler core.Handle || http.HandlerFunc || http.Handler
> add method
c.Get("/foo", func(c *core.Ctx){
c.SendString("Hello world")
})
func (*Core) ListenAndServe ¶
func (*Core) SetFuncMap ¶
SetFuncMap sets the FuncMap used for template.FuncMap.
type Ctx ¶
func (*Ctx) Cookie ¶
Cookie returns the named cookie provided in the request or ErrNoCookie if not found. And return the named cookie is unescaped. If multiple cookies match the given name, only one cookie will be returned.
func (*Ctx) FileAttachment ¶
FileAttachment writes the specified file into the body stream in an efficient way On the client side, the file will typically be downloaded with the given filename
func (*Ctx) FileFromFS ¶
func (c *Ctx) FileFromFS(filepath string, fs http.FileSystem)
FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.
func (*Ctx) FinalToJSON ¶
func (*Ctx) FormFile ¶
func (c *Ctx) FormFile(key string) (*multipart.FileHeader, error)
FormFile returns the first file for the provided form key. FormFile calls ParseMultipartForm and ParseForm if necessary.
func (*Ctx) FormValue ¶
FormValue Get query
key string def string default val optional
> GET /?name=Jack&id=
`
name := c.FromValue("name") // name = Jack
id := c.FromValue("id", "1") // id = 1 Because the default value is used
`
func (*Ctx) FromValues ¶
FromValues returns a slice of strings for a given query key.
func (*Ctx) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*Ctx) GetAs ¶
GetAs retrieve struct like c.Get("user").(User)
> Experimental function, problem unknown
func (*Ctx) GetDuration ¶
GetDuration returns the value associated with the key as a duration.
func (*Ctx) GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func (*Ctx) GetMap ¶
GetMap returns the value associated with the key as a map of interfaces.
> return map[string]interface{}
func (*Ctx) GetMapString ¶
GetMapString returns the value associated with the key as a map of strings.
> return map[string]string
func (*Ctx) GetMapStringSlice ¶
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
> return map[string][]string
func (*Ctx) GetStrings ¶
GetStrings String Slice returns the value associated with the key as a slice of strings.
func (*Ctx) ReadBody ¶
ReadBody binds the request body to a struct. It supports decoding the following content types based on the Content-Type header: application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data If none of the content types above are matched, it will return a ErrUnprocessableEntity error
out interface{} MIMEApplicationForm MIMEMultipartForm MIMETextXML must struct
func (*Ctx) RemoteIP ¶
RemoteIP parses the IP from Request.RemoteAddr, normalizes and returns the IP (without the port). It also checks if the remoteIP is a trusted proxy or not. In order to perform this validation, it will see if the IP is contained within at least one of the CIDR blocks defined by Engine.SetTrustedProxies()
func (*Ctx) SaveFile ¶
SaveFile upload file save to a folder
path = {root}/{dst}/{id}
@param
name string filename
dst string dst path
root string root path optional
id path optional type uid.UID, int, uint, int64,uint64
rename bool optional
return relPath, absPath
c.SaveFile("file", "/images")
(string) relpath "/images/10/favicon.png"
(string) abspath "/images/10/favicon.png"
c.SaveFile("file", "/images", "./static")
(string) relpath "/images/10/5hsbkthaadld/favicon.png"
(string) abspath "/static/images/10/5hsbkthaadld/favicon.png"
c.SaveFile("file", "/images", "./static", uid.New())
(string) relpath "/images/10/5hsbkthaadld/5hsbkthaadld.png"
(string) abspath "/static/images/10/5hsbkthaadld/5hsbkthaadld.png"
👇file 👇dst 👇root 👇id 👇rename
c.SaveFile("file", "/images", "./static", uid.New(), true)
(string) relpath "/images/10/5hsbkthaadld/5hsbkthaadld.png"
(string) abspath "/static/images/10/5hsbkthaadld/5hsbkthaadld.png"
func (*Ctx) SendStatus ¶
SendStatus send status code
func (*Ctx) SendString ¶
SendString send string to client
func (*Ctx) SetCookie ¶
SetCookie adds a Set-Cookie header to the ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
type ErrType ¶
type ErrType uint64
const ( // ErrTypeAny indicates any other error. ErrTypeAny ErrType = 1<<64 - 1 // ErrorTypeNu indicates any other error. ErrTypeNu = 2 )
type Error ¶
Error represents an error that occurred while handling a request.
type Handler ¶
type Handler struct {
Handlers map[string]struct{} // Record callable handle
// contains filtered or unexported fields
}
Handler base Handler
func (*Handler) Init ¶
func (h *Handler) Init()
Init do nothing wait children rewrite app start call this func
func (*Handler) Preload ¶
Preload do nothing wait children rewrite any request before call this func
func (*Handler) PushHandler ¶
PushHandler push list to PushHandler
type HandlerFuncs ¶
type HandlerFuncs []HandlerFunc
type InmemoryListener ¶
type InmemoryListener struct {
// contains filtered or unexported fields
}
InmemoryListener provides in-memory dialer<->net.Listener implementation.
It may be used either for fast in-process client<->server communications without network stack overhead or for client<->server tests.
func NewInmemoryListener ¶
func NewInmemoryListener() *InmemoryListener
NewInmemoryListener returns new in-memory dialer<->net.Listener.
func (*InmemoryListener) Accept ¶
func (ln *InmemoryListener) Accept() (net.Conn, error)
Accept implements net.Listener's Accept.
It is safe calling Accept from concurrently running goroutines.
Accept returns new connection per each Dial call.
func (*InmemoryListener) Addr ¶
func (ln *InmemoryListener) Addr() net.Addr
Addr implements net.Listener's Addr.
func (*InmemoryListener) Close ¶
func (ln *InmemoryListener) Close() error
Close implements net.Listener's Close.
type InvalidUnmarshalError ¶
An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type PipeConns ¶
type PipeConns struct {
// contains filtered or unexported fields
}
PipeConns provides bi-directional connection pipe, which use in-process memory as a transport.
PipeConns must be created by calling NewPipeConns.
PipeConns has the following additional features comparing to connections returned from net.Pipe():
- It is faster.
- It buffers Write calls, so there is no need to have concurrent goroutine calling Read in order to unblock each Write call.
- It supports read and write deadlines.
PipeConns is NOT safe for concurrent use by multiple goroutines!
func NewPipeConns ¶
func NewPipeConns() *PipeConns
NewPipeConns returns new bi-directional connection pipe.
PipeConns is NOT safe for concurrent use by multiple goroutines!
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
http.Hijacker
http.Flusher
// Returns the HTTP response status code of the current request.
Status() int
// Returns the number of bytes already written into the response http body.
// See Written()
Size() int
// Writes the string into the response body.
WriteString(string) (int, error)
// Returns true if the response body was already written.
Written() bool
// Forces to write the http header (status code + headers).
DoWriteHeader()
// get the http.Pusher for server push
Pusher() http.Pusher
}
ResponseWriter ...