Documentation
¶
Index ¶
- Constants
- Variables
- func GetVersion() string
- func GetVersionHeader() string
- type App
- func (a *App) AcquireContext(w http.ResponseWriter, r *http.Request) *Context
- func (a *App) Add(method, path string, handlers ...HandlerFunc) error
- func (a *App) All(path string, handlers ...HandlerFunc) error
- func (a *App) Any(path string, handlers ...HandlerFunc) error
- func (a *App) Connect(path string, handlers ...HandlerFunc) error
- func (a *App) Delete(path string, handlers ...HandlerFunc) error
- func (a *App) File(path, file string) error
- func (a *App) FileFS(path, file string, filesystem fs.FS) error
- func (a *App) FindRoute(method, path string) (RouteInfo, bool)
- func (a *App) Get(path string, handlers ...any) error
- func (a *App) Group(prefix string, handlers ...HandlerFunc) *Group
- func (a *App) Handle(spec RouteSpec) error
- func (a *App) Handler() http.Handler
- func (a *App) Head(path string, handlers ...HandlerFunc) error
- func (a *App) Listen(addr string) error
- func (a *App) ListenTLS(addr, certFile, keyFile string) error
- func (a *App) Match(methods []string, path string, handlers ...HandlerFunc) error
- func (a *App) MethodNotAllowed(handler HandlerFunc)
- func (a *App) Mount(prefix string, h http.Handler)
- func (a *App) NotFound(handler HandlerFunc)
- func (a *App) Options(path string, handlers ...HandlerFunc) error
- func (a *App) Patch(path string, handlers ...HandlerFunc) error
- func (a *App) Post(path string, handlers ...HandlerFunc) error
- func (a *App) Put(path string, handlers ...HandlerFunc) error
- func (a *App) ReleaseContext(c *Context)
- func (a *App) Route(prefix string, fn func(*Group), handlers ...HandlerFunc) *Group
- func (a *App) RouteByName(name string) (RouteInfo, bool)
- func (a *App) RouteNotFound(path string, handlers ...HandlerFunc) error
- func (a *App) Routes() []RouteInfo
- func (a *App) RoutesByMethod(method string) []RouteInfo
- func (a *App) RoutesByPrefix(prefix string) []RouteInfo
- func (a *App) Serve(ln net.Listener) error
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *App) Shutdown(ctx context.Context) error
- func (a *App) Static(prefix, root string, opts ...StaticOption) error
- func (a *App) StaticFS(prefix string, filesystem fs.FS, opts ...StaticOption) error
- func (a *App) Trace(path string, handlers ...HandlerFunc) error
- func (a *App) URL(name string, params ...string) (string, error)
- func (a *App) Use(handlers ...HandlerFunc)
- func (a *App) UsePrefix(prefix string, handlers ...HandlerFunc)
- type Bind
- func (b *Bind) All(v any) error
- func (b *Bind) Body(v any) error
- func (b *Bind) Form(v any) error
- func (b *Bind) Header(v any) error
- func (b *Bind) JSON(v any) error
- func (b *Bind) Path(v any) error
- func (b *Bind) Query(v any) error
- func (b *Bind) TOML(v any) error
- func (b *Bind) Text(v any) error
- func (b *Bind) XML(v any) error
- func (b *Bind) YAML(v any) error
- type BindError
- type Config
- type Context
- func (c *Context) AbortWithJSON(code int, v any) error
- func (c *Context) AbortWithStatus(code int) error
- func (c *Context) Accepts(types ...string) string
- func (c *Context) AppendHeader(key string, values ...string) *Context
- func (c *Context) Attachment(filePath string, name ...string) error
- func (c *Context) Bind() *Bind
- func (c *Context) Blob(status int, contentType string, b []byte) error
- func (c *Context) BodyBytes() ([]byte, error)
- func (c *Context) BodyString() (string, error)
- func (c *Context) ClearCookie(names ...string)
- func (c *Context) ContentType() string
- func (c *Context) Context() stdctx.Context
- func (c *Context) Cookie(name string) (*http.Cookie, error)
- func (c *Context) Cookies() []*http.Cookie
- func (c *Context) Copy() *Context
- func (c *Context) Data(contentType string, b []byte) error
- func (c *Context) Download(filePath string, name ...string) error
- func (c *Context) Error(err error)
- func (c *Context) Fail(err error) error
- func (c *Context) File(filePath string) error
- func (c *Context) FileFS(filePath string, filesystem fs.FS) error
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) FormFiles(name string) ([]*multipart.FileHeader, error)
- func (c *Context) FormValue(name string) string
- func (c *Context) FullPath() string
- func (c *Context) Get(key any) (any, bool)
- func (c *Context) GetBool(key any) bool
- func (c *Context) GetFloat64(key any) float64
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetInt(key any) int
- func (c *Context) GetInt64(key any) int64
- func (c *Context) GetString(key any) string
- func (c *Context) GetStringMap(key any) map[string]any
- func (c *Context) GetStringMapString(key any) map[string]string
- func (c *Context) GetStringMapStringSlice(key any) map[string][]string
- func (c *Context) GetStringSlice(key any) []string
- func (c *Context) HTML(data string) error
- func (c *Context) HTMLBlob(status int, b []byte) error
- func (c *Context) IP() string
- func (c *Context) IPs() []string
- func (c *Context) Inline(filePath string, name ...string) error
- func (c *Context) IsPreflight() bool
- func (c *Context) IsWebSocket() bool
- func (c *Context) JSON(v any) error
- func (c *Context) JSONBlob(status int, b []byte) error
- func (c *Context) JSONPretty(v any, indent string) error
- func (c *Context) LastError() error
- func (c *Context) Location(location string) *Context
- func (c *Context) Method() string
- func (c *Context) MultipartForm() (*multipart.Form, error)
- func (c *Context) MustGet(key any) any
- func (c *Context) Negotiate(status int, offers map[string]any) error
- func (c *Context) Next() error
- func (c *Context) NoContent() error
- func (c *Context) OriginalURL() string
- func (c *Context) Param(name string) string
- func (c *Context) ParamOr(name, fallback string) string
- func (c *Context) Path() string
- func (c *Context) PostForm(name string) string
- func (c *Context) PostFormArray(name string) []string
- func (c *Context) PostFormMap(name string) map[string]string
- func (c *Context) PostFormOr(name, fallback string) string
- func (c *Context) Query(name string) string
- func (c *Context) QueryArray(name string) []string
- func (c *Context) QueryMap(name string) map[string]string
- func (c *Context) QueryOr(name, fallback string) string
- func (c *Context) QueryValues() url.Values
- func (c *Context) Redirect(code int, location string) error
- func (c *Context) RemoteIP() string
- func (c *Context) Render(name string, data any) error
- func (c *Context) Request() *http.Request
- func (c *Context) RequestID() string
- func (c *Context) Route() RouteInfo
- func (c *Context) SSE(event SSEvent) error
- func (c *Context) SaveFile(file *multipart.FileHeader, dst string) error
- func (c *Context) Scheme() string
- func (c *Context) Secure() bool
- func (c *Context) Send(data any) error
- func (c *Context) Set(key any, value any)
- func (c *Context) SetContext(ctx stdctx.Context)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(key, value string) *Context
- func (c *Context) SetPath(path string)
- func (c *Context) SetRequest(r *http.Request)
- func (c *Context) SetSameSite(mode http.SameSite) *Context
- func (c *Context) SetWriter(w http.ResponseWriter)
- func (c *Context) Status(code int) *Context
- func (c *Context) Stream(contentType string, r io.Reader) error
- func (c *Context) String(data string) error
- func (c *Context) TOML(v any) error
- func (c *Context) Type(ext string) *Context
- func (c *Context) Validate(v any) error
- func (c *Context) Vary(fields ...string) *Context
- func (c *Context) Writer() http.ResponseWriter
- func (c *Context) XML(v any) error
- func (c *Context) XMLBlob(status int, b []byte) error
- func (c *Context) YAML(v any) error
- type ErrorHandler
- type Group
- func (g *Group) Add(method, routePath string, handlers ...HandlerFunc) error
- func (g *Group) All(path string, handlers ...HandlerFunc) error
- func (g *Group) Any(path string, handlers ...HandlerFunc) error
- func (g *Group) Connect(path string, handlers ...HandlerFunc) error
- func (g *Group) Delete(path string, handlers ...HandlerFunc) error
- func (g *Group) File(routePath, file string) error
- func (g *Group) FileFS(routePath, file string, filesystem fs.FS) error
- func (g *Group) Get(path string, handlers ...any) error
- func (g *Group) Group(prefix string, handlers ...HandlerFunc) *Group
- func (g *Group) Handle(spec RouteSpec) error
- func (g *Group) Head(path string, handlers ...HandlerFunc) error
- func (g *Group) Match(methods []string, routePath string, handlers ...HandlerFunc) error
- func (g *Group) Mount(prefix string, h http.Handler)
- func (g *Group) Options(path string, handlers ...HandlerFunc) error
- func (g *Group) Patch(path string, handlers ...HandlerFunc) error
- func (g *Group) Post(path string, handlers ...HandlerFunc) error
- func (g *Group) Put(path string, handlers ...HandlerFunc) error
- func (g *Group) Route(prefix string, fn func(*Group), handlers ...HandlerFunc) *Group
- func (g *Group) RouteNotFound(routePath string, handlers ...HandlerFunc) error
- func (g *Group) Static(prefix, root string, opts ...StaticOption) error
- func (g *Group) StaticFS(prefix string, filesystem fs.FS, opts ...StaticOption) error
- func (g *Group) Trace(path string, handlers ...HandlerFunc) error
- func (g *Group) Use(handlers ...HandlerFunc) *Group
- type HTTPError
- func (e *HTTPError) Error() string
- func (e *HTTPError) Unwrap() error
- func (e *HTTPError) WithCause(cause error) *HTTPError
- func (e *HTTPError) WithHeader(key, value string) *HTTPError
- func (e *HTTPError) WithMessage(message string) *HTTPError
- func (e *HTTPError) WithMeta(key string, value any) *HTTPError
- type HandlerFunc
- type JSONCodec
- type Map
- type Middleware
- type Renderer
- type RequestBinder
- type ResponseWriter
- type Route
- type RouteCache
- type RouteHandler
- type RouteHandlerMap
- type RouteInfo
- type RouteMap
- type RouteSpec
- type Router
- type SSEvent
- type StaticConfig
- type StaticOption
- type TemplateExecutor
- type TemplateRenderer
- func NewHTMLTemplateRenderer(engine *htmltemplate.Template, opts ...TemplateRendererOption) *TemplateRenderer
- func NewTemplateRenderer(engine TemplateExecutor, opts ...TemplateRendererOption) *TemplateRenderer
- func NewTextTemplateRenderer(engine *texttemplate.Template, opts ...TemplateRendererOption) *TemplateRenderer
- type TemplateRendererOption
- type Validator
Constants ¶
View Source
const ( ParamIdentifier = ':' WildcardIdentifier = '*' )
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" HeaderSecFetchSite = "Sec-Fetch-Site" 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" HeaderXCSRFToken = "X-CSRF-Token" 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" )
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 )
HTTP methods
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 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
View Source
const Version = "0.1.2"
Version is the current version of Zinc. This should be updated for each release.
Variables ¶
View Source
var ( ErrBadRequest = NewError(StatusBadRequest) ErrPaymentRequired = NewError(StatusPaymentRequired) ErrForbidden = NewError(StatusForbidden) ErrNotFound = NewError(StatusNotFound) ErrMethodNotAllowed = NewError(StatusMethodNotAllowed) ErrNotAcceptable = NewError(StatusNotAcceptable) ErrProxyAuthRequired = NewError(StatusProxyAuthRequired) ErrRequestTimeout = NewError(StatusRequestTimeout) ErrConflict = NewError(StatusConflict) ErrGone = NewError(StatusGone) ErrLengthRequired = NewError(StatusLengthRequired) ErrPreconditionFailed = NewError(StatusPreconditionFailed) ErrRequestEntityTooLarge = NewError(StatusRequestEntityTooLarge) ErrRequestURITooLong = NewError(StatusRequestURITooLong) ErrUnsupportedMediaType = NewError(StatusUnsupportedMediaType) ErrRequestedRangeNotSatisfiable = NewError(StatusRequestedRangeNotSatisfiable) ErrExpectationFailed = NewError(StatusExpectationFailed) ErrTeapot = NewError(StatusTeapot) ErrMisdirectedRequest = NewError(StatusMisdirectedRequest) ErrUnprocessableEntity = NewError(StatusUnprocessableEntity) ErrLocked = NewError(StatusLocked) ErrFailedDependency = NewError(StatusFailedDependency) ErrTooEarly = NewError(StatusTooEarly) ErrUpgradeRequired = NewError(StatusUpgradeRequired) ErrPreconditionRequired = NewError(StatusPreconditionRequired) ErrTooManyRequests = NewError(StatusTooManyRequests) ErrRequestHeaderFieldsTooLarge = NewError(StatusRequestHeaderFieldsTooLarge) ErrInternalServerError = NewError(StatusInternalServerError) ErrNotImplemented = NewError(StatusNotImplemented) ErrBadGateway = NewError(StatusBadGateway) ErrGatewayTimeout = NewError(StatusGatewayTimeout) ErrHTTPVersionNotSupported = NewError(StatusHTTPVersionNotSupported) ErrVariantAlsoNegotiates = NewError(StatusVariantAlsoNegotiates) ErrInsufficientStorage = NewError(StatusInsufficientStorage) ErrLoopDetected = NewError(StatusLoopDetected) ErrNotExtended = NewError(StatusNotExtended) ErrNetworkAuthenticationRequired = NewError(StatusNetworkAuthenticationRequired) )
View Source
var ( ErrTemplateEngineNotConfigured = errors.New("template engine is not configured") ErrTemplateNameRequired = errors.New("template name is required") ErrTemplateNotFound = errors.New("template not found") )
View Source
var DefaultConfig = Config{ ServerHeader: "", CaseSensitive: false, StrictRouting: false, AutoHead: true, AutoOptions: true, HandleMethodNotAllowed: true, BodyLimit: 4 << 20, ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, IdleTimeout: 120 * time.Second, ProxyHeader: "X-Forwarded-For", TrustedProxies: nil, RouteCacheSize: 1000, }
DefaultConfig is the baseline Zinc configuration.
View Source
var ErrResponseAlreadySent = errors.New("response already sent")
Functions ¶
func GetVersionHeader ¶
func GetVersionHeader() string
GetVersionHeader returns the full version string for HTTP headers.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func NewWithConfig ¶
func (*App) AcquireContext ¶ added in v0.1.0
func (*App) Match ¶
func (a *App) Match(methods []string, path string, handlers ...HandlerFunc) error
func (*App) MethodNotAllowed ¶
func (a *App) MethodNotAllowed(handler HandlerFunc)
func (*App) NotFound ¶
func (a *App) NotFound(handler HandlerFunc)
func (*App) ReleaseContext ¶ added in v0.1.0
func (*App) Route ¶
func (a *App) Route(prefix string, fn func(*Group), handlers ...HandlerFunc) *Group
func (*App) RouteNotFound ¶ added in v0.1.0
func (a *App) RouteNotFound(path string, handlers ...HandlerFunc) error
func (*App) RoutesByMethod ¶ added in v0.1.0
func (*App) RoutesByPrefix ¶ added in v0.1.0
func (*App) Use ¶
func (a *App) Use(handlers ...HandlerFunc)
func (*App) UsePrefix ¶
func (a *App) UsePrefix(prefix string, handlers ...HandlerFunc)
type Config ¶
type Config struct {
ServerHeader string
CaseSensitive bool
StrictRouting bool
AutoHead bool
AutoOptions bool
HandleMethodNotAllowed bool
BodyLimit int64
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
ProxyHeader string
TrustedProxies []string
RequestBinder RequestBinder
Validator Validator
Renderer Renderer
JSONCodec JSONCodec
ErrorHandler ErrorHandler
RouteCacheSize int
}
Config holds the application and server configuration.
type Context ¶
type Context struct {
PathParams params
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) *Context
func (*Context) AbortWithJSON ¶ added in v0.1.0
func (*Context) AbortWithStatus ¶ added in v0.1.0
func (*Context) AppendHeader ¶
func (*Context) BodyString ¶
func (*Context) ClearCookie ¶
func (*Context) ContentType ¶ added in v0.1.2
func (*Context) FormFiles ¶
func (c *Context) FormFiles(name string) ([]*multipart.FileHeader, error)
func (*Context) GetFloat64 ¶ added in v0.1.2
func (*Context) GetStringMap ¶ added in v0.1.2
func (*Context) GetStringMapString ¶ added in v0.1.2
func (*Context) GetStringMapStringSlice ¶ added in v0.1.2
func (*Context) GetStringSlice ¶ added in v0.1.2
func (*Context) IsPreflight ¶
func (*Context) IsWebSocket ¶
func (*Context) OriginalURL ¶
func (*Context) PostFormArray ¶ added in v0.1.2
func (*Context) PostFormMap ¶ added in v0.1.2
func (*Context) PostFormOr ¶ added in v0.1.2
func (*Context) QueryArray ¶ added in v0.1.2
func (*Context) QueryValues ¶
func (*Context) SetContext ¶
func (*Context) SetRequest ¶
func (*Context) SetSameSite ¶ added in v0.1.2
func (*Context) SetWriter ¶
func (c *Context) SetWriter(w http.ResponseWriter)
func (*Context) Writer ¶
func (c *Context) Writer() http.ResponseWriter
type ErrorHandler ¶
ErrorHandler handles an error returned from a Zinc handler.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) Match ¶
func (g *Group) Match(methods []string, routePath string, handlers ...HandlerFunc) error
func (*Group) Route ¶
func (g *Group) Route(prefix string, fn func(*Group), handlers ...HandlerFunc) *Group
func (*Group) RouteNotFound ¶ added in v0.1.0
func (g *Group) RouteNotFound(routePath string, handlers ...HandlerFunc) error
func (*Group) Use ¶
func (g *Group) Use(handlers ...HandlerFunc) *Group
type HTTPError ¶
HTTPError represents an HTTP error with a status code and optional message.
func (*HTTPError) WithHeader ¶ added in v0.1.0
func (*HTTPError) WithMessage ¶
type HandlerFunc ¶
func StringHandler ¶
func StringHandler(str string) HandlerFunc
func Wrap ¶
func Wrap(h http.Handler) HandlerFunc
func WrapFunc ¶
func WrapFunc(fn http.HandlerFunc) HandlerFunc
type Middleware ¶
type Middleware = HandlerFunc
type RequestBinder ¶ added in v0.1.1
type ResponseWriter ¶ added in v0.1.2
type ResponseWriter interface {
http.ResponseWriter
Status() int
BytesWritten() int
Written() bool
}
func WrapResponseWriter ¶ added in v0.1.2
func WrapResponseWriter(w http.ResponseWriter) ResponseWriter
type RouteCache ¶
type RouteCache struct {
// contains filtered or unexported fields
}
func NewRouteCache ¶
func NewRouteCache(size int) *RouteCache
type RouteHandler ¶
type RouteHandler = HandlerFunc
type RouteHandlerMap ¶
type RouteHandlerMap map[string]HandlerFunc
type RouteSpec ¶ added in v0.1.0
type RouteSpec struct {
Name string
Method string
Path string
Handler HandlerFunc
}
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
type StaticConfig ¶
type StaticOption ¶
type StaticOption func(*StaticConfig)
func WithStaticBrowse ¶
func WithStaticBrowse(browse bool) StaticOption
func WithStaticIndex ¶
func WithStaticIndex(index string) StaticOption
type TemplateExecutor ¶ added in v0.0.76
type TemplateRenderer ¶ added in v0.0.76
type TemplateRenderer struct {
Engine TemplateExecutor
// contains filtered or unexported fields
}
func NewHTMLTemplateRenderer ¶ added in v0.0.76
func NewHTMLTemplateRenderer(engine *htmltemplate.Template, opts ...TemplateRendererOption) *TemplateRenderer
func NewTemplateRenderer ¶ added in v0.0.76
func NewTemplateRenderer(engine TemplateExecutor, opts ...TemplateRendererOption) *TemplateRenderer
func NewTextTemplateRenderer ¶ added in v0.0.76
func NewTextTemplateRenderer(engine *texttemplate.Template, opts ...TemplateRendererOption) *TemplateRenderer
type TemplateRendererOption ¶ added in v0.0.76
type TemplateRendererOption func(*TemplateRenderer)
func WithTemplateSuffixes ¶ added in v0.0.76
func WithTemplateSuffixes(suffixes ...string) TemplateRendererOption
Source Files
¶
Click to show internal directories.
Click to hide internal directories.