Documentation ¶
Index ¶
- Constants
- Variables
- func Bind(destination any, data map[string][]string, tag string) error
- func ContextWithParams(ctx context.Context, params PathParams) context.Context
- func HandleUI(h http.Handler) http.Handler
- func UIFileServer(fs http.FileSystem) http.Handler
- type AfterServe
- type Create
- type Ctx
- type CtxBinding
- type CtxRender
- type DefaultCtx
- func (c *DefaultCtx) Bind(i any) (err error)
- func (c *DefaultCtx) BindBody(i any) error
- func (c *DefaultCtx) BindCtx(i any) error
- func (c *DefaultCtx) BindForm(i any) (err error)
- func (c *DefaultCtx) BindHeaders(i any) (err error)
- func (c *DefaultCtx) BindJSON(i any) error
- func (c *DefaultCtx) BindPath(i any) (err error)
- func (c *DefaultCtx) BindQuery(i any) (err error)
- func (c *DefaultCtx) Blob(status int, contentType string, data []byte) error
- func (c *DefaultCtx) Created(location string) error
- func (c *DefaultCtx) Debug() bool
- func (c *DefaultCtx) Get(key string) any
- func (c *DefaultCtx) HTML(status int, name string, obj any) error
- func (c *DefaultCtx) IndentedJSON(status int, obj any) error
- func (c *DefaultCtx) JSON(status int, obj any) error
- func (c *DefaultCtx) NegotiateFormat(offered ...string) string
- func (c *DefaultCtx) NoContent() error
- func (c *DefaultCtx) OK() error
- func (c *DefaultCtx) Redirect(code int, location string) error
- func (c *DefaultCtx) Render(status int, r render.Render) error
- func (c *DefaultCtx) Req() *Request
- func (c *DefaultCtx) Res() Response
- func (c *DefaultCtx) Reset(r *http.Request, w http.ResponseWriter)
- func (c *DefaultCtx) SSEvent(event string, data any) error
- func (c *DefaultCtx) Set(key string, value any)
- func (c *DefaultCtx) SetReq(req *Request)
- func (c *DefaultCtx) SetRes(res Response)
- func (c *DefaultCtx) Status(status int) error
- func (c *DefaultCtx) Store() map[string]any
- func (c *DefaultCtx) Stream(step func(w io.Writer) error) error
- func (c *DefaultCtx) String(status int, format string, data ...any) error
- func (c *DefaultCtx) Validate(i any) error
- type Delete
- type Error
- func NewErrBadRequest(err error, message ...string) *Error
- func NewErrConflict(err error, message ...string) *Error
- func NewErrForbidden(err error, message ...string) *Error
- func NewErrInternalServerError(err error, message ...string) *Error
- func NewErrMethodNotAllowed(err error, message ...string) *Error
- func NewErrNotFound(err error, message ...string) *Error
- func NewErrRequestEntityTooLarge(err error, message ...string) *Error
- func NewErrUnauthorized(err error, message ...string) *Error
- func NewErrUnprocessableEntity(err error, data any, message ...string) *Error
- func NewError(code int, err error, message ...string) *Error
- type ErrorHandler
- type ErrorTransform
- type FailedField
- type Handler
- type List
- type Map
- type Middleware
- type Option
- func WithAfterServe(as AfterServe) Option
- func WithErrorHandler(h ErrorHandler) Option
- func WithErrorTransform(et ErrorTransform) Option
- func WithHTMLRender(r render.HTMLRender) Option
- func WithMethodNotAllowed(h Handler) Option
- func WithMiddleware(mw ...Middleware) Option
- func WithNewCtxFunc(newCtxFunc func(*Wool, *http.Request, http.ResponseWriter) Ctx) Option
- func WithNotFoundHandler(h Handler) Option
- func WithOptionsHandler(h Handler) Option
- func WithValidator(v Validator) Option
- type PartiallyUpdate
- type PathParams
- type Request
- func (r *Request) Accept() []string
- func (r *Request) Clone(ctx context.Context) *Request
- func (r *Request) ContentType() string
- func (r *Request) FormValues() (url.Values, error)
- func (r *Request) IsForm() bool
- func (r *Request) IsJSON() bool
- func (r *Request) IsMultipartForm() bool
- func (r *Request) IsTLS() bool
- func (r *Request) PathParam(param string) string
- func (r *Request) PathParamID() string
- func (r *Request) PathParams() PathParams
- func (r *Request) QueryParam(name string) string
- func (r *Request) QueryParams() url.Values
- func (r *Request) WithContext(ctx context.Context) *Request
- type Response
- type Server
- type ServerConfig
- type Take
- type UIAssetWrapper
- type Update
- type Validator
- type Wool
- func (wool *Wool) AcquireCtx() Ctx
- func (wool *Wool) Add(pattern string, handler Handler, methods ...string)
- func (wool *Wool) CONNECT(pattern string, handler Handler)
- func (wool *Wool) CRUD(pattern string, resource any, mw ...Middleware)
- func (wool *Wool) DELETE(pattern string, handler Handler)
- func (wool *Wool) Debug(ctx context.Context) bool
- func (wool *Wool) Error(next Handler) Handler
- func (wool *Wool) GET(pattern string, handler Handler)
- func (wool *Wool) Group(pattern string, fn func(*Wool))
- func (wool *Wool) HEAD(pattern string, handler Handler)
- func (wool *Wool) MountHealth()
- func (wool *Wool) NewCtx(r *http.Request, w http.ResponseWriter) Ctx
- func (wool *Wool) OPTIONS(pattern string, handler Handler)
- func (wool *Wool) PATCH(pattern string, handler Handler)
- func (wool *Wool) POST(pattern string, handler Handler)
- func (wool *Wool) PUT(pattern string, handler Handler)
- func (wool *Wool) Recover(next Handler) Handler
- func (wool *Wool) ReleaseCtx(c Ctx)
- func (wool *Wool) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (wool *Wool) TRACE(pattern string, handler Handler)
- func (wool *Wool) UI(pattern string, fs http.FileSystem, methods ...string)
- func (wool *Wool) Use(mw ...Middleware)
Constants ¶
View Source
const ( MIMETextXML = "text/xml" MIMETextHTML = "text/html" MIMETextPlain = "text/plain" MIMETextJavaScript = "text/javascript" MIMETextEventStream = "text/event-stream" MIMEApplicationXML = "application/xml" MIMEApplicationJSON = "application/json" MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEOctetStream = "application/octet-stream" MIMEMultipartForm = "multipart/form-data" MIMEImageIcon = "image/x-icon" MIMETextXMLCharsetUTF8 = "text/xml; charset=utf-8" MIMETextHTMLCharsetUTF8 = "text/html; charset=utf-8" MIMETextPlainCharsetUTF8 = "text/plain; charset=utf-8" MIMETextJavaScriptCharsetUTF8 = "text/javascript; charset=utf-8" MIMETextEventStreamCharsetUTF8 = "text/event-stream; charset=utf-8" MIMEApplicationXMLCharsetUTF8 = "application/xml; charset=utf-8" MIMEApplicationJSONCharsetUTF8 = "application/json; charset=utf-8" )
MIME types that are commonly used
View Source
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" HeaderXForwardedScheme = "X-Forwarded-Scheme" 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" HeaderPermissionsPolicy = "Permissions-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" HeaderXRealIP = "X-Real-IP" HeaderXAccelBuffering = "X-Accel-Buffering" )
HTTP Headers were copied from net/http.
Variables ¶
View Source
var ( DefaultNotFoundHandler = func(c Ctx) error { return NewErrNotFound(nil) } DefaultMethodNotAllowed = func(Ctx) error { return NewErrMethodNotAllowed(nil) } DefaultOptionsHandler = func(c Ctx) error { return c.NoContent() } DefaultErrorHandler = func(c Ctx, err *Error) error { switch c.NegotiateFormat(MIMETextPlain, MIMETextHTML, MIMEApplicationJSON) { case MIMEApplicationJSON: return c.JSON(err.Code, err) default: if c.Debug() { return c.String(err.Code, "code=%d, message=%v, data=%v, developer_message=%s", err.Code, err.Message, err.Data, err.Developer) } return c.String(err.Code, "code=%d, message=%v, data=%v", err.Code, err.Message, err.Data) } } DefaultErrorTransform = func(err error) *Error { var e *Error if !errors.As(err, &e) { e = NewError(http.StatusInternalServerError, err) } return e } )
View Source
var DefaultMethods = []string{ http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace, }
View Source
var ErrStreamClosed = errors.New("http: Stream closed")
Functions ¶
func ContextWithParams ¶
func ContextWithParams(ctx context.Context, params PathParams) context.Context
func UIFileServer ¶
func UIFileServer(fs http.FileSystem) http.Handler
Types ¶
type Ctx ¶
type CtxBinding ¶
type CtxRender ¶
type CtxRender interface { Status(status int) error Render(status int, r render.Render) error Blob(status int, contentType string, data []byte) error JSON(status int, obj any) error IndentedJSON(status int, obj any) error HTML(status int, name string, obj any) error String(status int, format string, data ...any) error SSEvent(event string, data any) error Stream(step func(w io.Writer) error) error Redirect(code int, location string) error Created(location string) error NoContent() error OK() error }
type DefaultCtx ¶
type DefaultCtx struct {
// contains filtered or unexported fields
}
func (*DefaultCtx) Bind ¶
func (c *DefaultCtx) Bind(i any) (err error)
func (*DefaultCtx) BindBody ¶
func (c *DefaultCtx) BindBody(i any) error
func (*DefaultCtx) BindCtx ¶
func (c *DefaultCtx) BindCtx(i any) error
func (*DefaultCtx) BindForm ¶
func (c *DefaultCtx) BindForm(i any) (err error)
func (*DefaultCtx) BindHeaders ¶
func (c *DefaultCtx) BindHeaders(i any) (err error)
func (*DefaultCtx) BindJSON ¶
func (c *DefaultCtx) BindJSON(i any) error
func (*DefaultCtx) BindPath ¶
func (c *DefaultCtx) BindPath(i any) (err error)
func (*DefaultCtx) BindQuery ¶
func (c *DefaultCtx) BindQuery(i any) (err error)
func (*DefaultCtx) Blob ¶
func (c *DefaultCtx) Blob(status int, contentType string, data []byte) error
func (*DefaultCtx) Created ¶
func (c *DefaultCtx) Created(location string) error
func (*DefaultCtx) Debug ¶
func (c *DefaultCtx) Debug() bool
func (*DefaultCtx) Get ¶
func (c *DefaultCtx) Get(key string) any
func (*DefaultCtx) IndentedJSON ¶
func (c *DefaultCtx) IndentedJSON(status int, obj any) error
func (*DefaultCtx) NegotiateFormat ¶
func (c *DefaultCtx) NegotiateFormat(offered ...string) string
func (*DefaultCtx) NoContent ¶
func (c *DefaultCtx) NoContent() error
func (*DefaultCtx) OK ¶
func (c *DefaultCtx) OK() error
func (*DefaultCtx) Req ¶
func (c *DefaultCtx) Req() *Request
func (*DefaultCtx) Res ¶
func (c *DefaultCtx) Res() Response
func (*DefaultCtx) Reset ¶
func (c *DefaultCtx) Reset(r *http.Request, w http.ResponseWriter)
func (*DefaultCtx) Set ¶
func (c *DefaultCtx) Set(key string, value any)
func (*DefaultCtx) SetReq ¶
func (c *DefaultCtx) SetReq(req *Request)
func (*DefaultCtx) SetRes ¶
func (c *DefaultCtx) SetRes(res Response)
func (*DefaultCtx) Status ¶
func (c *DefaultCtx) Status(status int) error
func (*DefaultCtx) Store ¶
func (c *DefaultCtx) Store() map[string]any
func (*DefaultCtx) String ¶
func (c *DefaultCtx) String(status int, format string, data ...any) error
func (*DefaultCtx) Validate ¶
func (c *DefaultCtx) Validate(i any) error
type Error ¶
type Error struct { Code int `json:"code,omitempty"` Message string `json:"message,omitempty"` Data any `json:"data,omitempty"` Developer string `json:"developer_message,omitempty"` Internal error `json:"-"` }
func NewErrBadRequest ¶
func NewErrConflict ¶
func NewErrForbidden ¶
func NewErrMethodNotAllowed ¶
func NewErrNotFound ¶
func NewErrUnauthorized ¶
type ErrorHandler ¶
type ErrorTransform ¶
type FailedField ¶
type Middleware ¶
func ToMiddleware ¶
func ToMiddleware(wrapper func(http.Handler) http.Handler) Middleware
type Option ¶
type Option func(*Wool)
func WithAfterServe ¶
func WithAfterServe(as AfterServe) Option
func WithErrorHandler ¶
func WithErrorHandler(h ErrorHandler) Option
func WithErrorTransform ¶
func WithErrorTransform(et ErrorTransform) Option
func WithHTMLRender ¶
func WithHTMLRender(r render.HTMLRender) Option
func WithMethodNotAllowed ¶
func WithMiddleware ¶
func WithMiddleware(mw ...Middleware) Option
func WithNewCtxFunc ¶
func WithNotFoundHandler ¶
func WithOptionsHandler ¶
func WithValidator ¶
type PartiallyUpdate ¶
type PathParams ¶
func ParamsFromContext ¶
func ParamsFromContext(ctx context.Context) PathParams
type Request ¶
func (*Request) ContentType ¶
func (*Request) IsMultipartForm ¶
func (*Request) PathParamID ¶
func (*Request) PathParams ¶
func (r *Request) PathParams() PathParams
func (*Request) QueryParam ¶
func (*Request) QueryParams ¶
type Response ¶
type Response interface { http.ResponseWriter http.Hijacker http.Flusher Pusher() http.Pusher Status() int Size() int64 Written() bool WriteString(s string) (int, error) WriteHeaderNow() }
func NewResponse ¶
func NewResponse(w http.ResponseWriter, logger *slog.Logger) Response
type Server ¶
type ServerConfig ¶
type ServerConfig struct { DisableHTTP2 bool `mapstructure:"disable_http2"` HidePort bool `mapstructure:"hide_port"` CertPath string `mapstructure:"cert_path"` CertFile string `mapstructure:"cert_file"` KeyFile string `mapstructure:"key_file"` Address string `mapstructure:"address"` Network string `mapstructure:"network"` MaxHeaderBytes int `mapstructure:"max_header_bytes"` ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"` ReadTimeout time.Duration `mapstructure:"read_timeout"` WriteTimeout time.Duration `mapstructure:"write_timeout"` IdleTimeout time.Duration `mapstructure:"idle_timeout"` GracefulTimeout time.Duration `mapstructure:"graceful_timeout"` }
func (*ServerConfig) Init ¶
func (cfg *ServerConfig) Init()
type UIAssetWrapper ¶
type UIAssetWrapper struct {
FileSystem http.FileSystem
}
type Validator ¶
func NewValidator ¶
func NewValidator() Validator
type Wool ¶
type Wool struct { Log *slog.Logger NewCtxFunc func(wool *Wool, r *http.Request, w http.ResponseWriter) Ctx HTMLRender render.HTMLRender NotFoundHandler Handler MethodNotAllowed Handler OptionsHandler Handler ErrorHandler ErrorHandler ErrorTransform ErrorTransform AfterServe AfterServe Validator Validator // contains filtered or unexported fields }
func (*Wool) AcquireCtx ¶
func (*Wool) MountHealth ¶
func (wool *Wool) MountHealth()
func (*Wool) ReleaseCtx ¶
func (*Wool) Use ¶
func (wool *Wool) Use(mw ...Middleware)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.