sha

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: Unlicense Imports: 37 Imported by: 0

README

sha

the pinyin for 沙(sand) is shā

Documentation

Index

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
	StatusUnauthorized                 = 401 // RFC 7235, 3.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
	StatusUnavailableForLegalReasons   = 451 // RFC 7725, 3

	StatusInternalServerError           = 500 // RFC 7231, 6.6.1
	StatusNotImplemented                = 501 // RFC 7231, 6.6.2
	StatusBadGateway                    = 502 // RFC 7231, 6.6.3
	StatusServiceUnavailable            = 503 // RFC 7231, 6.6.4
	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 AddStatusCode(v int, phrase string)

func DisableCompress

func DisableCompress()

DisableCompress keep raw response body when debugging

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)

func UseRBAC

func UseRBAC(router Router, options *rbac.Options)

Types

type CookieOptions

type CookieOptions struct {
	Domain   string
	Path     string
	MaxAge   int64
	Expires  time.Time
	Secure   bool
	HTTPOnly bool
	SameSite _SameSiteVal
}

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

type Form struct {
	utils.Kvs
}

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

func (form *Form) FromURLEncoded(p []byte)

type FormFile

type FormFile struct {
	Name     string
	FileName string
	Header   Header
	// contains filtered or unexported fields
}

func (*FormFile) Data

func (file *FormFile) Data() []byte

func (*FormFile) Read added in v0.0.5

func (file *FormFile) Read(p []byte) (int, error)

func (*FormFile) Save

func (file *FormFile) Save(name string) error

func (*FormFile) Seek added in v0.0.5

func (file *FormFile) Seek(offset int64, whence int) (int64, error)

type FormFiles

type FormFiles []*FormFile

func (FormFiles) Get

func (files FormFiles) Get(name string) *FormFile

func (FormFiles) GetAll

func (files FormFiles) GetAll(name string) []*FormFile

type HTTPError added in v0.0.5

type HTTPError interface {
	Error() string
	StatusCode() int
}

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 HTTPProxy added in v0.0.5

type HTTPProxy struct {
	Address   string
	AuthFunc  func() (string, string)
	TLSConfig *tls.Config
	IsTLS     bool
}

type HTTPResponseError added in v0.0.5

type HTTPResponseError interface {
	HTTPError
	WriteHeader(*Header)
	Body() []byte
}

type HTTPServerProtocol added in v0.0.5

type HTTPServerProtocol interface {
	ServeConn(ctx context.Context, conn net.Conn)
}

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 struct {
	utils.Kvs
	// contains filtered or unexported fields
}

func (*Header) ContainsUTF8Key added in v0.0.5

func (header *Header) ContainsUTF8Key()

func (*Header) ContentLength

func (header *Header) ContentLength() int

func (*Header) ContentType

func (header *Header) ContentType() []byte

func (*Header) Del added in v0.0.5

func (header *Header) Del(key string)

func (*Header) Get added in v0.0.5

func (header *Header) Get(key string) ([]byte, bool)

func (*Header) GetAll added in v0.0.5

func (header *Header) GetAll(key string) [][]byte

func (*Header) IsContainsUTF8Key added in v0.0.5

func (header *Header) IsContainsUTF8Key() bool

func (*Header) Reset added in v0.0.5

func (header *Header) Reset()

func (*Header) Set added in v0.0.5

func (header *Header) Set(key string, v []byte) *utils.KvItem

func (*Header) SetContentLength

func (header *Header) SetContentLength(v int64)

func (*Header) SetContentType

func (header *Header) SetContentType(v string)

func (*Header) SetString added in v0.0.5

func (header *Header) SetString(key, v string) *utils.KvItem

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) NewGroup added in v0.0.5

func (m *Mux) NewGroup(prefix string) Router

func (*Mux) ServeDocument added in v0.0.5

func (m *Mux) ServeDocument(method, path string, middleware ...Middleware)

func (*Mux) String added in v0.0.5

func (m *Mux) String() string

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 NewGroup added in v0.0.6

func NewGroup(prefix string) *MuxGroup

func (*MuxGroup) BindTo added in v0.0.6

func (m *MuxGroup) BindTo(router Router)

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) NewGroup added in v0.0.6

func (m *MuxGroup) NewGroup(prefix string) Router

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 OriginToName func(origin []byte) string

type Request

type Request struct {
	URL URL
	// contains filtered or unexported fields
}

func (*Request) Body added in v0.0.5

func (req *Request) Body() *bytes.Buffer

func (*Request) BodyForm

func (req *Request) BodyForm() *Form

func (*Request) BodyFormValue

func (req *Request) BodyFormValue(name string) ([]byte, bool)

func (*Request) BodyFormValues

func (req *Request) BodyFormValues(name string) [][]byte

func (*Request) BodyRaw

func (req *Request) BodyRaw() []byte

func (*Request) CookieValue

func (req *Request) CookieValue(key string) ([]byte, bool)

func (*Request) Cookies added in v0.0.5

func (req *Request) Cookies() *utils.Kvs

func (*Request) Files

func (req *Request) Files() FormFiles

func (*Request) HTTPVersion added in v0.0.5

func (req *Request) HTTPVersion() []byte

func (*Request) Header

func (p *Request) Header() *Header

func (*Request) Method

func (req *Request) Method() []byte

func (*Request) Path

func (req *Request) Path() string

func (*Request) Query

func (req *Request) Query() *Form

func (*Request) QueryValue

func (req *Request) QueryValue(name string) ([]byte, bool)

func (*Request) QueryValues

func (req *Request) QueryValues(name string) [][]byte

func (*Request) RawPath

func (req *Request) RawPath() []byte

func (*Request) Reset

func (req *Request) Reset()

func (*Request) SetFormBody added in v0.0.5

func (req *Request) SetFormBody(form *Form) *Request

func (*Request) SetJSONBody added in v0.0.5

func (req *Request) SetJSONBody(v interface{}) error

func (*Request) SetMethod added in v0.0.5

func (req *Request) SetMethod(method string) *Request

func (*Request) SetMultiValueMapBody added in v0.0.5

func (req *Request) SetMultiValueMapBody(fv utils.MultiValueMap) *Request

func (*Request) SetPath added in v0.0.5

func (req *Request) SetPath(path []byte) *Request

func (*Request) SetPathString added in v0.0.5

func (req *Request) SetPathString(path string) *Request

func (*Request) SetVersion added in v0.0.5

func (req *Request) SetVersion(version string) *Request

func (*Request) UnixNano added in v0.0.5

func (p *Request) UnixNano() int64

func (*Request) Write added in v0.0.5

func (p *Request) Write(v []byte) (int, error)

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

func (ctx *RequestCtx) AutoCompress()

br > deflate > gzip

func (*RequestCtx) Close

func (ctx *RequestCtx) Close()

http connection

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

func (ctx *RequestCtx) Deadline() (deadline time.Time, ok bool)

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

func (ctx *RequestCtx) Write(p []byte) (int, error)

func (*RequestCtx) WriteFile

func (ctx *RequestCtx) WriteFile(f io.Reader, ext string)

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

type RequestCtxPool struct {
	sync.Pool
	// contains filtered or unexported fields
}

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) Body added in v0.0.5

func (res *Response) Body() *bytes.Buffer

func (*Response) HTTPVersion added in v0.0.5

func (res *Response) HTTPVersion() []byte

func (*Response) Header

func (p *Response) Header() *Header

func (*Response) Phrase added in v0.0.5

func (res *Response) Phrase() string

func (*Response) ResetBody added in v0.0.5

func (res *Response) ResetBody()

func (*Response) SetCookie

func (res *Response) SetCookie(k, v string, options *CookieOptions)

func (*Response) SetHTTPVersion added in v0.0.5

func (res *Response) SetHTTPVersion(v string) *Response

func (*Response) SetStatusCode

func (res *Response) SetStatusCode(v int) *Response

func (*Response) StatusCode added in v0.0.5

func (res *Response) StatusCode() int

func (*Response) UnixNano added in v0.0.5

func (p *Response) UnixNano() int64

func (*Response) Write

func (res *Response) Write(p []byte) (int, error)

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 Default

func Default() *Server

func New

func New(ctx context.Context, pool *RequestCtxPool, opt *ServerOptions) *Server

func (*Server) BeforeAccept

func (s *Server) BeforeAccept(fn func(s *Server))

func (*Server) IsTLS

func (s *Server) IsTLS() bool

func (*Server) Listen added in v0.0.5

func (s *Server) Listen() net.Listener

func (*Server) ListenAndServe

func (s *Server) ListenAndServe()

func (*Server) RequestCtxPool added in v0.0.5

func (s *Server) RequestCtxPool() *RequestCtxPool

func (*Server) Serve added in v0.0.5

func (s *Server) Serve(l net.Listener)

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 Template added in v0.0.5

type Template interface {
	Execute(ctx context.Context, v interface{}) error
}

type URL added in v0.0.5

type URL struct {
	Host   []byte
	Port   []byte
	Path   []byte
	Query  []byte
	Params URLParams
	// contains filtered or unexported fields
}

type URLParams

type URLParams struct {
	utils.Kvs
}

func (*URLParams) GetInt

func (up *URLParams) GetInt(name string, base int) (int64, bool)

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

type WebsocketHandlerFunc added in v0.0.5

type WebsocketHandlerFunc func(ctx context.Context, req *Request, conn *websocket.Conn)

Directories

Path Synopsis
dao

Jump to

Keyboard shortcuts

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