Documentation ¶
Index ¶
- Constants
- Variables
- func AddStatusCode(v int, phrase string)
- func DisableCompress()
- func ListenAndServe(addr string, handler RequestHandler)
- func RecoverByErr(v error, fn ErrorHandler)
- func RecoverByType(t reflect.Type, fn ErrorHandler)
- func RedirectPermanently(uri string)
- func RedirectTemporarily(uri string)
- func ReleaseRequestCtx(ctx *RequestCtx)
- func UseRBAC(router Router, options *rbac.Options)
- type CookieOptions
- type CorsOptions
- type ErrorHandler
- type Form
- type FormFile
- type FormFiles
- type HTTPError
- type HTTPOptions
- type HTTPProxy
- type HTTPResponseError
- type HTTPServerProtocol
- type HTTPSession
- type HandlerOptions
- type Header
- func (header *Header) ContainsUTF8Key()
- func (header *Header) ContentLength() int
- func (header *Header) ContentType() []byte
- func (header *Header) Del(key string)
- func (header *Header) Get(key string) ([]byte, bool)
- func (header *Header) GetAll(key string) [][]byte
- func (header *Header) IsContainsUTF8Key() bool
- func (header *Header) Reset()
- func (header *Header) Set(key string, v []byte) *utils.KvItem
- func (header *Header) SetContentLength(v int64)
- func (header *Header) SetContentType(v string)
- func (header *Header) SetString(key, v string) *utils.KvItem
- type Middleware
- type MiddlewareFunc
- type Mux
- func (m *Mux) File(opt *HandlerOptions, method, path, filepath string)
- func (m *Mux) FileSystem(opt *HandlerOptions, method, path string, fs http.FileSystem, autoIndex bool)
- func (m *Mux) HTTP(method, path string, handler RequestHandler)
- func (m *Mux) HTTPWithOptions(opt *HandlerOptions, method, path string, handler RequestHandler)
- func (m *Mux) Handle(ctx *RequestCtx)
- func (m *Mux) NewGroup(prefix string) Router
- func (m *Mux) ServeDocument(method, path string, middleware ...Middleware)
- func (m *Mux) String() string
- func (m *Mux) Use(middlewares ...Middleware)
- func (m *Mux) Websocket(path string, handlerFunc WebsocketHandlerFunc, opt *HandlerOptions)
- type MuxGroup
- func (m *MuxGroup) BindTo(router Router)
- func (m *MuxGroup) File(opt *HandlerOptions, method, path, filepath string)
- func (m *MuxGroup) FileSystem(opt *HandlerOptions, method, path string, fs http.FileSystem, autoIndex bool)
- func (m *MuxGroup) HTTP(method, path string, handler RequestHandler)
- func (m *MuxGroup) HTTPWithOptions(opt *HandlerOptions, method, path string, handler RequestHandler)
- func (m *MuxGroup) NewGroup(prefix string) Router
- func (m *MuxGroup) Use(middlewares ...Middleware)
- func (m *MuxGroup) Websocket(path string, handlerFunc WebsocketHandlerFunc, opt *HandlerOptions)
- type MuxOptions
- type OriginToName
- type Request
- func (req *Request) Body() *bytes.Buffer
- func (req *Request) BodyForm() *Form
- func (req *Request) BodyFormValue(name string) ([]byte, bool)
- func (req *Request) BodyFormValues(name string) [][]byte
- func (req *Request) BodyRaw() []byte
- func (req *Request) CookieValue(key string) ([]byte, bool)
- func (req *Request) Cookies() *utils.Kvs
- func (req *Request) Files() FormFiles
- func (req *Request) HTTPVersion() []byte
- func (p *Request) Header() *Header
- func (req *Request) Method() []byte
- func (req *Request) Path() string
- func (req *Request) Query() *Form
- func (req *Request) QueryValue(name string) ([]byte, bool)
- func (req *Request) QueryValues(name string) [][]byte
- func (req *Request) RawPath() []byte
- func (req *Request) Reset()
- func (req *Request) SetFormBody(form *Form) *Request
- func (req *Request) SetJSONBody(v interface{}) error
- func (req *Request) SetMethod(method string) *Request
- func (req *Request) SetMultiValueMapBody(fv utils.MultiValueMap) *Request
- func (req *Request) SetPath(path []byte) *Request
- func (req *Request) SetPathString(path string) *Request
- func (req *Request) SetVersion(version string) *Request
- func (p *Request) UnixNano() int64
- func (p *Request) Write(v []byte) (int, error)
- type RequestCtx
- func (ctx *RequestCtx) AutoCompress()
- func (ctx *RequestCtx) Close()
- func (ctx *RequestCtx) CompressBrotli()
- func (ctx *RequestCtx) CompressDeflate()
- func (ctx *RequestCtx) CompressGzip()
- func (ctx *RequestCtx) Context() context.Context
- func (ctx *RequestCtx) Deadline() (deadline time.Time, ok bool)
- func (ctx *RequestCtx) Done() <-chan struct{}
- func (ctx *RequestCtx) Err() error
- func (ctx *RequestCtx) GetCustomData(key string) interface{}
- func (ctx *RequestCtx) Hijack() net.Conn
- func (ctx *RequestCtx) IsCONNECT() bool
- func (ctx *RequestCtx) IsCustomMethod() bool
- func (ctx *RequestCtx) IsDELETE() bool
- func (ctx *RequestCtx) IsGET() bool
- func (ctx *RequestCtx) IsHEAD() bool
- func (ctx *RequestCtx) IsOPTIONS() bool
- func (ctx *RequestCtx) IsPATCH() bool
- func (ctx *RequestCtx) IsPOST() bool
- func (ctx *RequestCtx) IsPUT() bool
- func (ctx *RequestCtx) IsTLS() bool
- func (ctx *RequestCtx) IsTRACE() bool
- func (ctx *RequestCtx) Keep()
- func (ctx *RequestCtx) MustValidateForm(dist interface{})
- func (ctx *RequestCtx) MustValidateJSON(dist interface{})
- func (ctx *RequestCtx) RemoteAddr() net.Addr
- func (ctx *RequestCtx) Reset()
- func (ctx *RequestCtx) ReturnTo(pool *RequestCtxPool)
- func (ctx *RequestCtx) SetConnection(conn net.Conn)
- func (ctx *RequestCtx) SetCustomData(key string, value interface{})
- func (ctx *RequestCtx) SetError(v interface{})
- func (ctx *RequestCtx) SetParentContext(pctx context.Context)
- func (ctx *RequestCtx) UpgradeProtocol() string
- func (ctx *RequestCtx) ValidateForm(dist interface{}) HTTPError
- func (ctx *RequestCtx) ValidateJSON(dist interface{}) HTTPError
- func (ctx *RequestCtx) Value(key interface{}) interface{}
- func (ctx *RequestCtx) VisitCustomData(fn func(key []byte, v interface{}) bool)
- func (ctx *RequestCtx) Write(p []byte) (int, error)
- func (ctx *RequestCtx) WriteFile(f io.Reader, ext string)
- func (ctx *RequestCtx) WriteHTML(v []byte)
- func (ctx *RequestCtx) WriteJSON(v interface{})
- func (ctx *RequestCtx) WriteString(s string) (int, error)
- func (ctx *RequestCtx) WriteTemplate(t Template, data interface{}) error
- type RequestCtxPool
- type RequestHandler
- type RequestHandlerFunc
- type Response
- func (res *Response) Body() *bytes.Buffer
- func (res *Response) HTTPVersion() []byte
- func (p *Response) Header() *Header
- func (res *Response) Phrase() string
- func (res *Response) ResetBody()
- func (res *Response) SetCookie(k, v string, options *CookieOptions)
- func (res *Response) SetHTTPVersion(v string) *Response
- func (res *Response) SetStatusCode(v int) *Response
- func (res *Response) StatusCode() int
- func (p *Response) UnixNano() int64
- func (res *Response) Write(p []byte) (int, error)
- type Router
- type Server
- func (s *Server) BeforeAccept(fn func(s *Server))
- func (s *Server) IsTLS() bool
- func (s *Server) Listen() net.Listener
- func (s *Server) ListenAndServe()
- func (s *Server) RequestCtxPool() *RequestCtxPool
- func (s *Server) Serve(l net.Listener)
- func (s *Server) SetHTTPProtocol(protocol HTTPServerProtocol)
- func (s *Server) SetWebSocketProtocol(protocol WebSocketProtocol)
- type ServerOptions
- type SessionOptions
- type StatusError
- type Template
- type URL
- type URLParams
- type WebSocketOptions
- type WebSocketProtocol
- type WebsocketHandlerFunc
Constants ¶
View Source
const ( CookeSameSiteDefault = _SameSiteVal("") CookieSameSiteLax = _SameSiteVal("lax") CookieSameSiteStrict = _SameSiteVal("strict") CookieSameSizeNone = _SameSiteVal("none") )
View Source
const ( // Authentication HeaderAuthorization = "Authorization" HeaderProxyAuthenticate = "Proxy-Authenticate" HeaderProxyAuthorization = "Proxy-Authorization" HeaderWWWAuthenticate = "WWW-Authenticate" // Caching HeaderAge = "Age" HeaderCacheControl = "Cache-Control" HeaderClearSiteData = "Clear-Site-Data" HeaderExpires = "Expires" HeaderPragma = "Pragma" HeaderWarning = "Warning" // Client hints HeaderAcceptCH = "Accept-CH" HeaderAcceptCHLifetime = "Accept-CH-Lifetime" HeaderContentDPR = "Content-DPR" HeaderDPR = "DPR" HeaderEarlyData = "Early-Data" HeaderSaveData = "Save-Data" HeaderViewportWidth = "Viewport-Width" HeaderWidth = "Width" // Conditionals HeaderETag = "ETag" HeaderIfMatch = "If-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderLastModified = "Last-Modified" HeaderVary = "Vary" // HTTPSession management HeaderConnection = "Connection" HeaderKeepAlive = "Keep-Alive" // Content negotiation HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" // Controls HeaderCookie = "CookieValue" HeaderExpect = "Expect" HeaderMaxForwards = "Max-Forwards" HeaderSetCookie = "Set-CookieValue" // CORS 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" // Do Not Track HeaderDNT = "DNT" HeaderTk = "Tk" // Downloads HeaderContentDisposition = "Content-Disposition" // Message body information HeaderContentEncoding = "Content-Encoding" HeaderContentLanguage = "Content-Language" HeaderContentLength = "Content-Length" HeaderContentLocation = "Content-Location" HeaderContentType = "Content-Type" // Proxies HeaderForwarded = "Forwarded" HeaderVia = "Via" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedHost = "X-Forwarded-Host" HeaderXForwardedProto = "X-Forwarded-Proto" // Redirects HeaderLocation = "Location" // Request context HeaderFrom = "From" HeaderHost = "Host" HeaderReferer = "Referer" HeaderReferrerPolicy = "Referrer-Policy" HeaderUserAgent = "User-Agent" // Response context HeaderAllow = "Allow" HeaderServer = "Server" // Range requests HeaderAcceptRanges = "Accept-Ranges" HeaderContentRange = "Content-Range" HeaderIfRange = "If-Range" HeaderRange = "Range" // Security 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" // Server-sent event HeaderLastEventID = "Last-Event-ID" HeaderNEL = "NEL" HeaderPingFrom = "Ping-From" HeaderPingTo = "Ping-To" HeaderReportTo = "Report-To" // Transfer coding HeaderTE = "TE" HeaderTrailer = "Trailer" HeaderTransferEncoding = "Transfer-Encoding" // WebSockets HeaderSecWebSocketAccept = "Sec-WebSocket-Accept" HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" HeaderSecWebSocketKey = "Sec-WebSocket-Key" HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol" HeaderSecWebSocketVersion = "Sec-WebSocket-Version" // Other 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" HeaderXRequestedWith = "X-Requested-With" HeaderXRobotsTag = "X-Robots-Tag" HeaderXUACompatible = "X-UA-Compatible" )
copied from https://github.com/valyala/fasthttp/blob/master/headers.go Headers
View Source
const ( HTTPVersion11 = "HTTP/1.1" HTTPVersion10 = "HTTP/1.0" )
View Source
const ( MethodGet = "GET" // RFC 7231, 4.3.1 MethodHead = "HEAD" // RFC 7231, 4.3.2 MethodPost = "POST" // RFC 7231, 4.3.3 MethodPut = "PUT" // RFC 7231, 4.3.4 MethodPatch = "PATCH" // RFC 5789 MethodDelete = "DELETE" // RFC 7231, 4.3.5 MethodConnect = "CONNECT" // RFC 7231, 4.3.6 MethodOptions = "OPTIONS" // RFC 7231, 4.3.7 MethodTrace = "TRACE" // RFC 7231, 4.3.8 )
View Source
const ( MIMEJson = "application/json" MIMEForm = "application/x-www-form-urlencoded" MIMEMultiPart = "multipart/form-data" MIMEText = "text/plain" MIMEMarkdown = "text/markdown" MIMEHtml = "text/html" MIMEPng = "image/png" MIMEJpeg = "image/jpeg" )
View Source
const ( CtxKeyServer = _CtxVKey(iota) CtxKeyConnection )
View Source
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 StatusNonAuthoritativeInfo = 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 )
Variables ¶
View Source
var ( CompressLevelGzip = gzip.DefaultCompression CompressLevelDeflate = flate.DefaultCompression CompressLevelBrotli = brotli.DefaultCompression )
View Source
var DirList func(ctx *RequestCtx, f http.File)
View Source
var ErrBadHTTPPocketData = errors.New("sha.http: bad http pocket data")
View Source
var ErrCanceled = errors.New("sha.http: canceled")
View Source
var ErrRequestHijacked = errors.New("sha: request is already hijacked")
View Source
var ErrUnknownResponseStatusCode = fmt.Errorf("sha: unknown response status code")
View Source
var NonTLSRequestResponseMessage = `HTTP/1.0 400 Bad Request
Connection: close
Content-Length: 47
Client sent an HTTP request to an HTTPS server.`
View Source
var UnSupportedTLSSubProtocolRequestResponseMessage = `HTTP/1.0 510 Not Implemented
Connection: close
Content-Length: 25
UnSupportedTLSSubProtocol`
Functions ¶
func AddStatusCode ¶
func ListenAndServe ¶
func ListenAndServe(addr string, handler RequestHandler)
func RecoverByErr ¶
func RecoverByErr(v error, fn ErrorHandler)
func RecoverByType ¶
func RecoverByType(t reflect.Type, fn ErrorHandler)
func RedirectPermanently ¶
func RedirectPermanently(uri string)
func RedirectTemporarily ¶
func RedirectTemporarily(uri string)
func ReleaseRequestCtx ¶
func ReleaseRequestCtx(ctx *RequestCtx)
Types ¶
type CookieOptions ¶
type CorsOptions ¶
type CorsOptions struct { Name string `json:"name" toml:"name"` AllowMethods string `json:"allow_methods" toml:"allow-methods"` AllowHeaders string `json:"allow_headers" toml:"allow-headers"` ExposeHeaders string `json:"expose_headers" toml:"expose-headers"` AllowCredentials bool `json:"allow_credentials" toml:"allow-credentials"` MaxAge int64 `json:"max_age" toml:"max-age"` }
type ErrorHandler ¶
type ErrorHandler func(ctx *RequestCtx, v interface{})
type Form ¶
func (*Form) EncodeToBuf ¶ added in v0.0.5
func (form *Form) EncodeToBuf(w interface { io.ByteWriter io.Writer })
func (*Form) FromURLEncoded ¶ added in v0.0.5
type FormFile ¶
type HTTPOptions ¶ added in v0.0.5
type HTTPOptions struct { MaxFirstLineSize int `json:"max_first_line_size"` MaxHeaderPartSize int `json:"max_header_part_size"` MaxBodySize int `json:"max_body_size"` ReadBufferSize int `json:"read_buffer_size"` SendBufferSize int `json:"send_buffer_size"` MaxBodyBufferSize int `json:"max_body_buffer_size" toml:"max-body-buffer-size"` }
type HTTPResponseError ¶ added in v0.0.5
type HTTPServerProtocol ¶ added in v0.0.5
type HTTPSession ¶ added in v0.0.5
type HTTPSession struct {
// contains filtered or unexported fields
}
func NewHTTPSession ¶ added in v0.0.5
func NewHTTPSession(address string, isTLS bool, opt *SessionOptions) *HTTPSession
func (*HTTPSession) Close ¶ added in v0.0.5
func (s *HTTPSession) Close() error
func (*HTTPSession) OpenConn ¶ added in v0.0.5
func (s *HTTPSession) OpenConn(ctx context.Context) error
func (*HTTPSession) Reconnect ¶ added in v0.0.5
func (s *HTTPSession) Reconnect()
func (*HTTPSession) Send ¶ added in v0.0.5
func (s *HTTPSession) Send(ctx *RequestCtx) error
type HandlerOptions ¶ added in v0.0.5
type HandlerOptions struct { Middlewares []Middleware Document validator.Document }
type Header ¶
func (*Header) ContainsUTF8Key ¶ added in v0.0.5
func (header *Header) ContainsUTF8Key()
func (*Header) ContentLength ¶
func (*Header) ContentType ¶
func (*Header) IsContainsUTF8Key ¶ added in v0.0.5
func (*Header) SetContentLength ¶
func (*Header) SetContentType ¶
type Middleware ¶
type Middleware interface {
Process(ctx *RequestCtx, next func())
}
func MustGrantedAll ¶
func MustGrantedAll(permissions ...string) Middleware
func MustGrantedAny ¶
func MustGrantedAny(permissions ...string) Middleware
type MiddlewareFunc ¶
type MiddlewareFunc func(ctx *RequestCtx, next func())
func (MiddlewareFunc) Process ¶
func (f MiddlewareFunc) Process(ctx *RequestCtx, next func())
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
func NewMux ¶
func NewMux(opt *MuxOptions) *Mux
func (*Mux) File ¶
func (m *Mux) File(opt *HandlerOptions, method, path, filepath string)
func (*Mux) FileSystem ¶ added in v0.0.5
func (m *Mux) FileSystem(opt *HandlerOptions, method, path string, fs http.FileSystem, autoIndex bool)
func (*Mux) HTTP ¶
func (m *Mux) HTTP(method, path string, handler RequestHandler)
func (*Mux) HTTPWithOptions ¶ added in v0.0.5
func (m *Mux) HTTPWithOptions(opt *HandlerOptions, method, path string, handler RequestHandler)
func (*Mux) Handle ¶
func (m *Mux) Handle(ctx *RequestCtx)
func (*Mux) ServeDocument ¶ added in v0.0.5
func (m *Mux) ServeDocument(method, path string, middleware ...Middleware)
func (*Mux) Use ¶
func (m *Mux) Use(middlewares ...Middleware)
func (*Mux) Websocket ¶ added in v0.0.5
func (m *Mux) Websocket(path string, handlerFunc WebsocketHandlerFunc, opt *HandlerOptions)
type MuxGroup ¶ added in v0.0.6
type MuxGroup struct {
// contains filtered or unexported fields
}
func (*MuxGroup) File ¶ added in v0.0.6
func (m *MuxGroup) File(opt *HandlerOptions, method, path, filepath string)
func (*MuxGroup) FileSystem ¶ added in v0.0.6
func (m *MuxGroup) FileSystem(opt *HandlerOptions, method, path string, fs http.FileSystem, autoIndex bool)
func (*MuxGroup) HTTP ¶ added in v0.0.6
func (m *MuxGroup) HTTP(method, path string, handler RequestHandler)
func (*MuxGroup) HTTPWithOptions ¶ added in v0.0.6
func (m *MuxGroup) HTTPWithOptions(opt *HandlerOptions, method, path string, handler RequestHandler)
func (*MuxGroup) Use ¶ added in v0.0.6
func (m *MuxGroup) Use(middlewares ...Middleware)
func (*MuxGroup) Websocket ¶ added in v0.0.6
func (m *MuxGroup) Websocket(path string, handlerFunc WebsocketHandlerFunc, opt *HandlerOptions)
type MuxOptions ¶ added in v0.0.5
type MuxOptions struct { Prefix string `json:"prefix" toml:"prefix"` DoTrailingSlashRedirect bool `json:"tsr" toml:"tsr"` AutoHandleOptions bool `json:"aho" toml:"aho"` NoFound func(ctx *RequestCtx) `json:"-" toml:"-"` MethodNotAllowed func(ctx *RequestCtx) `json:"-" toml:"-"` CORS []*CorsOptions `json:"cors" toml:"cors"` CORSOriginToName func(origin []byte) string `json:"-" toml:"-"` Recover func(ctx *RequestCtx, v interface{}) `json:"recover" toml:"-"` }
type OriginToName ¶ added in v0.0.5
type Request ¶
type Request struct { URL URL // contains filtered or unexported fields }
func (*Request) BodyFormValues ¶
func (*Request) HTTPVersion ¶ added in v0.0.5
func (*Request) QueryValues ¶
func (*Request) SetFormBody ¶ added in v0.0.5
func (*Request) SetJSONBody ¶ added in v0.0.5
func (*Request) SetMultiValueMapBody ¶ added in v0.0.5
func (req *Request) SetMultiValueMapBody(fv utils.MultiValueMap) *Request
func (*Request) SetPathString ¶ added in v0.0.5
func (*Request) SetVersion ¶ added in v0.0.5
type RequestCtx ¶
type RequestCtx struct { Request Request Response Response // contains filtered or unexported fields }
func AcquireRequestCtx ¶ added in v0.0.5
func AcquireRequestCtx() *RequestCtx
func Unwrap ¶ added in v0.0.5
func Unwrap(ctx context.Context) *RequestCtx
func (*RequestCtx) CompressBrotli ¶
func (ctx *RequestCtx) CompressBrotli()
func (*RequestCtx) CompressDeflate ¶
func (ctx *RequestCtx) CompressDeflate()
func (*RequestCtx) CompressGzip ¶
func (ctx *RequestCtx) CompressGzip()
func (*RequestCtx) Context ¶ added in v0.0.5
func (ctx *RequestCtx) Context() context.Context
func (*RequestCtx) Done ¶
func (ctx *RequestCtx) Done() <-chan struct{}
func (*RequestCtx) Err ¶
func (ctx *RequestCtx) Err() error
func (*RequestCtx) GetCustomData ¶
func (ctx *RequestCtx) GetCustomData(key string) interface{}
func (*RequestCtx) Hijack ¶
func (ctx *RequestCtx) Hijack() net.Conn
func (*RequestCtx) IsCONNECT ¶
func (ctx *RequestCtx) IsCONNECT() bool
func (*RequestCtx) IsCustomMethod ¶
func (ctx *RequestCtx) IsCustomMethod() bool
func (*RequestCtx) IsDELETE ¶
func (ctx *RequestCtx) IsDELETE() bool
func (*RequestCtx) IsGET ¶
func (ctx *RequestCtx) IsGET() bool
func (*RequestCtx) IsHEAD ¶
func (ctx *RequestCtx) IsHEAD() bool
func (*RequestCtx) IsOPTIONS ¶
func (ctx *RequestCtx) IsOPTIONS() bool
func (*RequestCtx) IsPATCH ¶
func (ctx *RequestCtx) IsPATCH() bool
func (*RequestCtx) IsPOST ¶
func (ctx *RequestCtx) IsPOST() bool
func (*RequestCtx) IsPUT ¶
func (ctx *RequestCtx) IsPUT() bool
func (*RequestCtx) IsTLS ¶
func (ctx *RequestCtx) IsTLS() bool
func (*RequestCtx) IsTRACE ¶
func (ctx *RequestCtx) IsTRACE() bool
func (*RequestCtx) Keep ¶ added in v0.0.5
func (ctx *RequestCtx) Keep()
func (*RequestCtx) MustValidateForm ¶ added in v0.0.5
func (ctx *RequestCtx) MustValidateForm(dist interface{})
func (*RequestCtx) MustValidateJSON ¶
func (ctx *RequestCtx) MustValidateJSON(dist interface{})
func (*RequestCtx) RemoteAddr ¶
func (ctx *RequestCtx) RemoteAddr() net.Addr
func (*RequestCtx) Reset ¶
func (ctx *RequestCtx) Reset()
func (*RequestCtx) ReturnTo ¶ added in v0.0.5
func (ctx *RequestCtx) ReturnTo(pool *RequestCtxPool)
func (*RequestCtx) SetConnection ¶ added in v0.0.5
func (ctx *RequestCtx) SetConnection(conn net.Conn)
func (*RequestCtx) SetCustomData ¶
func (ctx *RequestCtx) SetCustomData(key string, value interface{})
custom data
func (*RequestCtx) SetError ¶ added in v0.0.5
func (ctx *RequestCtx) SetError(v interface{})
func (*RequestCtx) SetParentContext ¶ added in v0.0.5
func (ctx *RequestCtx) SetParentContext(pctx context.Context)
context.Context
func (*RequestCtx) UpgradeProtocol ¶
func (ctx *RequestCtx) UpgradeProtocol() string
func (*RequestCtx) ValidateForm ¶ added in v0.0.5
func (ctx *RequestCtx) ValidateForm(dist interface{}) HTTPError
pointer -> interface
func (*RequestCtx) ValidateJSON ¶
func (ctx *RequestCtx) ValidateJSON(dist interface{}) HTTPError
func (*RequestCtx) Value ¶
func (ctx *RequestCtx) Value(key interface{}) interface{}
func (*RequestCtx) VisitCustomData ¶ added in v0.0.5
func (ctx *RequestCtx) VisitCustomData(fn func(key []byte, v interface{}) bool)
func (*RequestCtx) WriteHTML ¶
func (ctx *RequestCtx) WriteHTML(v []byte)
func (*RequestCtx) WriteJSON ¶
func (ctx *RequestCtx) WriteJSON(v interface{})
func (*RequestCtx) WriteString ¶
func (ctx *RequestCtx) WriteString(s string) (int, error)
func (*RequestCtx) WriteTemplate ¶
func (ctx *RequestCtx) WriteTemplate(t Template, data interface{}) error
type RequestCtxPool ¶ added in v0.0.5
func DefaultRequestCtxPool ¶ added in v0.0.5
func DefaultRequestCtxPool() *RequestCtxPool
func NewRequestCtxPool ¶ added in v0.0.5
func NewRequestCtxPool(opt *HTTPOptions) *RequestCtxPool
func (*RequestCtxPool) Acquire ¶ added in v0.0.5
func (p *RequestCtxPool) Acquire() *RequestCtx
func (*RequestCtxPool) Release ¶ added in v0.0.5
func (p *RequestCtxPool) Release(ctx *RequestCtx)
type RequestHandler ¶
type RequestHandler interface {
Handle(ctx *RequestCtx)
}
func NewEmbedFSHandler ¶ added in v0.0.5
func NewEmbedFSHandler(fs *embed.FS, modTime time.Time, pathRewrite func(ctx *RequestCtx) string) RequestHandler
type RequestHandlerFunc ¶
type RequestHandlerFunc func(ctx *RequestCtx)
func (RequestHandlerFunc) Handle ¶
func (fn RequestHandlerFunc) Handle(ctx *RequestCtx)
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func (*Response) HTTPVersion ¶ added in v0.0.5
func (*Response) SetCookie ¶
func (res *Response) SetCookie(k, v string, options *CookieOptions)
func (*Response) SetHTTPVersion ¶ added in v0.0.5
func (*Response) SetStatusCode ¶
func (*Response) StatusCode ¶ added in v0.0.5
type Router ¶
type Router interface { HTTPWithOptions(opt *HandlerOptions, method, path string, handler RequestHandler) HTTP(method, path string, handler RequestHandler) Websocket(path string, handlerFunc WebsocketHandlerFunc, opt *HandlerOptions) FileSystem(opt *HandlerOptions, method, path string, fs http.FileSystem, autoIndex bool) File(opt *HandlerOptions, method, path, filepath string) Use(middlewares ...Middleware) NewGroup(prefix string) Router }
type Server ¶
type Server struct { OnConnectionAccepted func(conn net.Conn) bool Handler RequestHandler // contains filtered or unexported fields }
func New ¶
func New(ctx context.Context, pool *RequestCtxPool, opt *ServerOptions) *Server
func (*Server) BeforeAccept ¶
func (*Server) ListenAndServe ¶
func (s *Server) ListenAndServe()
func (*Server) RequestCtxPool ¶ added in v0.0.5
func (s *Server) RequestCtxPool() *RequestCtxPool
func (*Server) SetHTTPProtocol ¶ added in v0.0.6
func (s *Server) SetHTTPProtocol(protocol HTTPServerProtocol)
func (*Server) SetWebSocketProtocol ¶ added in v0.0.6
func (s *Server) SetWebSocketProtocol(protocol WebSocketProtocol)
type ServerOptions ¶ added in v0.0.6
type ServerOptions struct { Addr string `json:"addr" toml:"addr"` TLS struct { AutoCertDomains []string `json:"auto_cert_domains" toml:"auto-cert-domains"` Key string `json:"key" toml:"key"` Cert string `json:"cert" toml:"cert"` } `json:"tls" toml:"tls"` MaxConnectionKeepAlive utils.TomlDuration `json:"max_connection_keep_alive" toml:"max-connection-keep-alive"` ReadTimeout utils.TomlDuration `json:"read_timeout" toml:"read-timeout"` IdleTimeout utils.TomlDuration `json:"idle_timeout" toml:"idle-timeout"` WriteTimeout utils.TomlDuration `json:"write_timeout" toml:"write-timeout"` }
type SessionOptions ¶ added in v0.0.5
type SessionOptions struct { HTTPOptions *HTTPOptions HTTPProxy HTTPProxy InsecureSkipVerify bool TLSConfig *tls.Config RequestCtxPreChecker func(ctx *RequestCtx) }
type StatusError ¶
type StatusError int
func (StatusError) Body ¶
func (err StatusError) Body() []byte
func (StatusError) Error ¶
func (err StatusError) Error() string
func (StatusError) StatusCode ¶
func (err StatusError) StatusCode() int
func (StatusError) WriteHeader ¶
func (err StatusError) WriteHeader(_ *Header)
type WebSocketOptions ¶ added in v0.0.5
type WebSocketOptions struct { ReadBufferSize int WriteBufferSize int EnableCompression bool SelectSubprotocol func(ctx *RequestCtx) string }
type WebSocketProtocol ¶
type WebSocketProtocol interface { Handshake(ctx *RequestCtx) (string, bool, bool) Hijack(ctx *RequestCtx, subprotocol string, compress bool) *websocket.Conn }
func NewWebSocketProtocol ¶
func NewWebSocketProtocol(opt *WebSocketOptions) WebSocketProtocol
Source Files ¶
- client.go
- compress.go
- cookie.go
- ctx.go
- ctx.userdata.go
- ctx.validate.go
- ctx.validator.former.go
- ctx_pool.go
- error.go
- form.go
- fs.go
- fs_embed.go
- handler.go
- header.go
- headers.go
- http1x.go
- http1x.output.go
- http1x.parse.go
- http1x.pocket.go
- methods.go
- mimes.go
- rbac.go
- request.go
- response.go
- route.cors.go
- route.recover.go
- router.group.go
- router.interface.go
- router.mux.document.go
- router.mux.go
- router.radix.node.go
- router.radix.others.go
- router.radix.tree.go
- router.radix.types.go
- server.go
- status.go
- websocket.go
Click to show internal directories.
Click to hide internal directories.