Documentation
¶
Index ¶
- Constants
- Variables
- func ContentDispositionAttachment(filename string) string
- func ContentDispositionInline(filename string) string
- func Validate(v *ValidationError) error
- type BodyFn
- type Context
- func (c *Context) Accept() string
- func (c *Context) AcceptEncoding() string
- func (c *Context) AcceptLanguage() string
- func (c *Context) AccessControlRequestHeaders() ([]string, bool)
- func (c *Context) AccessControlRequestMethod() string
- func (c *Context) Authorization() string
- func (c *Context) BindJSON(data any) *Responsedeprecated
- func (c *Context) BindJson(data any) *Response
- func (c *Context) BindJsonOptional(data any) (bool, *Response)
- func (c *Context) CacheControl() string
- func (c *Context) ClientIP() string
- func (c *Context) ConditionalIfMatch(localEtag string) *Response
- func (c *Context) ConditionalIfModifiedSince(lastModified ...time.Time) *Response
- func (c *Context) ConditionalIfNoneMatch(localEtag string) *Response
- func (c *Context) ConditionalIfUnmodifiedSince(lastModified ...time.Time) *Response
- func (c *Context) Connection() string
- func (c *Context) ContentDisposition() string
- func (c *Context) ContentEncoding() string
- func (c *Context) ContentLanguage() string
- func (c *Context) ContentLength() (int64, bool)
- func (c *Context) ContentLocation() string
- func (c *Context) ContentType() string
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) Cookies() []*http.Cookie
- func (c *Context) Date() (time.Time, bool)
- func (c *Context) Deadline() (time.Time, bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) Expect() string
- func (c *Context) FormValues() url.Values
- func (c *Context) Forwarded() string
- func (c *Context) From() string
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) GetRawData() ([]byte, error)
- func (c *Context) HasQuery(key string) bool
- func (c *Context) Header(name string) string
- func (c *Context) Host() string
- func (c *Context) HxBoosted() bool
- func (c *Context) HxCurrentUrl() string
- func (c *Context) HxHistoryRestoreRequest() bool
- func (c *Context) HxPrompt() string
- func (c *Context) HxRequest() bool
- func (c *Context) HxTarget() string
- func (c *Context) HxTrigger() string
- func (c *Context) HxTriggerName() string
- func (c *Context) IfMatch() string
- func (c *Context) IfModifiedSince() (time.Time, bool, error)
- func (c *Context) IfNoneMatch() string
- func (c *Context) IfRange() string
- func (c *Context) IfUnmodifiedSince() (time.Time, bool, error)
- func (c *Context) IntQuery(key string) (int, *Response)
- func (c *Context) IntQueryOrDefault(key string, defaultValue int) (int, *Response)
- func (c *Context) KeepAlive() string
- func (c *Context) Link() string
- func (c *Context) MaxForwards() (int, bool, error)
- func (c *Context) MustGet(key string) any
- func (c *Context) Origin() string
- func (c *Context) PathValue(name string) string
- func (c *Context) Prefer() string
- func (c *Context) ProxyAuthorization() string
- func (c *Context) Query(key string) string
- func (c *Context) QueryArray(key string) (values []string, ok bool)
- func (c *Context) Range() string
- func (c *Context) Referer() string
- func (c *Context) RemoteIP() string
- func (c *Context) Request() *http.Request
- func (c *Context) SecFetchDest() string
- func (c *Context) SecFetchMode() string
- func (c *Context) SecFetchSite() string
- func (c *Context) SecFetchUser() bool
- func (c *Context) SecPurpose() string
- func (c *Context) Server() string
- func (c *Context) ServiceWorker() bool
- func (c *Context) ServiceWorkerNavigationPreload() string
- func (c *Context) Set(key string, value any)
- func (c *Context) StringQuery(key string) (string, *Response)
- func (c *Context) StringQueryOrDefault(key string, defaultValue string) (string, *Response)
- func (c *Context) TE() string
- func (c *Context) Trailer() string
- func (c *Context) TransferEncoding() string
- func (c *Context) UpgradeInsecureRequests() (bool, bool)
- func (c *Context) UserAgent() string
- func (c *Context) Value(key any) any
- func (c *Context) Via() string
- func (c *Context) WithContext(ctx context.Context) *Context
- type ErrorDto
- type Group
- func (g *Group) ANY(path string, handler Handler, middleware ...Middleware)
- func (g *Group) DELETE(path string, handler Handler, middleware ...Middleware)
- func (g *Group) GET(path string, handler Handler, middleware ...Middleware)
- func (g *Group) Group(path string, middleware ...Middleware) *Group
- func (g *Group) HEAD(path string, handler Handler, middleware ...Middleware)
- func (g *Group) OPTIONS(path string, handler Handler, middleware ...Middleware)
- func (g *Group) PATCH(path string, handler Handler, middleware ...Middleware)
- func (g *Group) POST(path string, handler Handler, middleware ...Middleware)
- func (g *Group) PUT(path string, handler Handler, middleware ...Middleware)
- type Handler
- type IPResolver
- type Middleware
- type Response
- func (r *Response) Accept(value string) *Response
- func (r *Response) AcceptEncoding(value string) *Response
- func (r *Response) AcceptPatch(value string) *Response
- func (r *Response) AcceptPost(value string) *Response
- func (r *Response) AcceptRanges() *Response
- func (r *Response) AccessControlAllowCredentials() *Response
- func (r *Response) AccessControlAllowHeaders(headers ...string) *Response
- func (r *Response) AccessControlAllowMethods(methods ...string) *Response
- func (r *Response) AccessControlAllowOrigin(origin string) *Response
- func (r *Response) AccessControlExposeHeaders(headers ...string) *Response
- func (r *Response) AccessControlMaxAge(maxAge int) *Response
- func (r *Response) AfterWrite(fn func()) *Response
- func (r *Response) Age(deltaSeconds int) *Response
- func (r *Response) Allow(methods ...string) *Response
- func (r *Response) BadRequest(body ...any) *Response
- func (r *Response) Body(contentType string, data []byte) *Response
- func (r *Response) BodyFn(contentType string, bodyFn BodyFn) *Response
- func (r *Response) BodyReader(contentType string, reader io.Reader) *Response
- func (r *Response) CacheControl(directive string) *Response
- func (r *Response) ClearSiteData(directive string) *Response
- func (r *Response) Conflict(body ...any) *Response
- func (r *Response) Connection(value string) *Response
- func (r *Response) ContentDisposition(disposition string) *Response
- func (r *Response) ContentEncoding(encoding string) *Response
- func (r *Response) ContentLanguage(language string) *Response
- func (r *Response) ContentLength(length int64) *Response
- func (r *Response) ContentLocation(location string) *Response
- func (r *Response) ContentRange(value string) *Response
- func (r *Response) ContentSecurityPolicy(directive string) *Response
- func (r *Response) ContentSecurityPolicyReportOnly(directive string) *Response
- func (r *Response) ContentType(contentType string) *Response
- func (r *Response) Cookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool) *Response
- func (r *Response) CookieRaw(cookie *http.Cookie) *Response
- func (r *Response) Created(body ...any) *Response
- func (r *Response) CrossOriginEmbedderPolicy(policy string) *Response
- func (r *Response) CrossOriginOpenerPolicy(policy string) *Response
- func (r *Response) CrossOriginResourcePolicy(policy string) *Response
- func (r *Response) Date(t time.Time) *Response
- func (r *Response) ETag(etag string) *Response
- func (r *Response) Error(err error) *Response
- func (r *Response) Expires(t time.Time) *Response
- func (r *Response) Forbidden(body ...any) *Response
- func (r *Response) Found(location string) *Response
- func (r *Response) Header(key, value string) *Response
- func (r *Response) Html(html string) *Response
- func (r *Response) HxLocation(location string) *Response
- func (r *Response) HxPushUrl(url string) *Response
- func (r *Response) HxRedirect(location string) *Response
- func (r *Response) HxRefresh() *Response
- func (r *Response) HxReplaceUrl(url string) *Response
- func (r *Response) HxReselect(selector string) *Response
- func (r *Response) HxReswap(value string) *Response
- func (r *Response) HxRetarget(selector string) *Response
- func (r *Response) HxTrigger(event string) *Response
- func (r *Response) HxTriggerAfterSettle(event string) *Response
- func (r *Response) HxTriggerAfterSwap(event string) *Response
- func (r *Response) InternalServerError(body ...any) *Response
- func (r *Response) Json(data any) *Response
- func (r *Response) KeepAlive(timeout int, max int) *Response
- func (r *Response) LastModified(t time.Time) *Response
- func (r *Response) Link(link string) *Response
- func (r *Response) Location(location string) *Response
- func (r *Response) MethodNotAllowed(body ...any) *Response
- func (r *Response) MovedPermanently(location string) *Response
- func (r *Response) NoContent() *Response
- func (r *Response) NoVarySearch(rules string) *Response
- func (r *Response) NotAcceptable(body ...any) *Response
- func (r *Response) NotFound(body ...any) *Response
- func (r *Response) NotModified() *Response
- func (r *Response) PreconditionFailed() *Response
- func (r *Response) PreferenceApplied(preference string) *Response
- func (r *Response) ProxyAuthRequired(body ...any) *Response
- func (r *Response) ProxyAuthenticate(challenge string) *Response
- func (r *Response) ReferrerPolicy(policy string) *Response
- func (r *Response) Refresh(timeSeconds int, url string) *Response
- func (r *Response) ReportingEndpoints(endpoints ...string) *Response
- func (r *Response) RetryAfterDate(t time.Time) *Response
- func (r *Response) RetryAfterSeconds(seconds int) *Response
- func (r *Response) Server(server string) *Response
- func (r *Response) ServerTiming(timing string) *Response
- func (r *Response) ServiceWorkerAllowed(scope string) *Response
- func (r *Response) SourceMap(url string) *Response
- func (r *Response) Status(status int) *Response
- func (r *Response) StrictTransportSecurity(value string) *Response
- func (r *Response) Text(text string) *Response
- func (r *Response) TimingAllowOrigin(origin string) *Response
- func (r *Response) Trailer(headerNames string) *Response
- func (r *Response) TransferEncoding(encodings ...string) *Response
- func (r *Response) Unauthorized(body ...any) *Response
- func (r *Response) Vary(headers ...string) *Response
- func (r *Response) Via(via string) *Response
- func (r *Response) Write(w http.ResponseWriter) error
- func (r *Response) WwwHauthenticate(challenge string) *Response
- func (r *Response) XContentTypeOptions() *Response
- func (r *Response) XFrameOptions(directive string) *Response
- func (r *Response) XPermittedCrossDomainPolicies(directive string) *Response
- func (r *Response) XPoweredBy(application string) *Response
- type Server
- func (s *Server) ANY(path string, handler Handler, middleware ...Middleware)
- func (s *Server) DELETE(path string, handler Handler, middleware ...Middleware)
- func (s *Server) GET(path string, handler Handler, middleware ...Middleware)
- func (s *Server) Group(path string, middleware ...Middleware) *Group
- func (s *Server) HEAD(path string, handler Handler, middleware ...Middleware)
- func (s *Server) Handle(pattern string, handler http.Handler)
- func (s *Server) HandleFunc(pattern string, handler http.HandlerFunc)
- func (s *Server) Handler() http.Handler
- func (s *Server) ListenAndServe(address string) error
- func (s *Server) OPTIONS(path string, handler Handler, middleware ...Middleware)
- func (s *Server) PATCH(path string, handler Handler, middleware ...Middleware)
- func (s *Server) POST(path string, handler Handler, middleware ...Middleware)
- func (s *Server) PUT(path string, handler Handler, middleware ...Middleware)
- func (s *Server) SetMaxMultipartMemory(max int64) *Server
- func (s *Server) SetRemoteIPHeaders(headers ...string) *Server
- func (s *Server) SetTrustRemoteIdHeaders(trust bool) *Server
- func (s *Server) Use(middleware ...Middleware) *Server
- type Validatable
- type ValidationError
- func Require(field, code, message string, cond bool, prev *ValidationError) *ValidationError
- func RequireEnumValue[T comparable](field string, value T, allowed []T, prev *ValidationError) *ValidationError
- func RequireEnumValueIndexed[T comparable](fieldFormat string, index int, value T, allowed []T, prev *ValidationError) *ValidationError
- func RequireIndexed(fieldFormat string, index int, code string, messageFormat string, cond bool, ...) *ValidationError
- func RequireMaxLength(field string, max int, value string, prev *ValidationError) *ValidationError
- func RequireMaxLengthIndexed(fieldFormat string, index int, max int, value string, prev *ValidationError) *ValidationError
- func RequireMaxLengthSlice[T any](field string, max int, value []T, prev *ValidationError) *ValidationError
- func RequireMaxLengthSliceIndexed[T any](fieldFormat string, index int, max int, value []T, prev *ValidationError) *ValidationError
- func RequireMinLength(field string, min int, value string, prev *ValidationError) *ValidationError
- func RequireMinLengthIndexed(fieldFormat string, index int, min int, value string, prev *ValidationError) *ValidationError
- func RequireMinLengthSlice[T any](field string, min int, value []T, prev *ValidationError) *ValidationError
- func RequireMinLengthSliceIndexed[T any](fieldFormat string, index int, min int, value []T, prev *ValidationError) *ValidationError
- func RequireNotEmpty(field string, value string, prev *ValidationError) *ValidationError
- func RequireNotEmptyIndexed(fieldFormat string, index int, value string, prev *ValidationError) *ValidationError
- func RequireNotEmptySlice[T any](field string, value []T, prev *ValidationError) *ValidationError
- func RequireNotEmptySliceIndexed[T any](fieldFormat string, index int, value []T, prev *ValidationError) *ValidationError
- func RequireRegex(field string, value string, pattern *regexp.Regexp, prev *ValidationError) *ValidationError
- func RequireRegexIndexed(fieldFormat string, index int, value string, pattern *regexp.Regexp, ...) *ValidationError
- type Violation
Constants ¶
const ( SecFetchSiteCrossSite = "cross-site" SecFetchSiteSameOrigin = "same-origin" SecFetchSiteSameSite = "same-site" SecFetchSiteNone = "none" SecFetchModeCors = "cors" SecFetchModeNoCors = "no-cors" SecFetchModeSameOrigin = "same-origin" SecFetchModeWebsocket = "websocket" SecFetchDestAudio = "audio" SecFetchDestAudioWorklet = "audioworklet" SecFetchDestDocument = "document" SecFetchDestEmbed = "embed" SecFetchDestEmpty = "empty" SecFetchDestFencedframe = "fencedframe" SecFetchDestFont = "font" SecFetchDestFrame = "frame" SecFetchDestIframe = "iframe" SecFetchDestImage = "image" SecFetchDestManifest = "manifest" SecFetchDestObject = "object" SecFetchDestPaintworklet = "paintworklet" SecFetchDestReport = "report" SecFetchDestScript = "script" SecFetchDestServiceworker = "serviceworker" SecFetchDestStyle = "style" SecFetchDestTrack = "track" SecFetchDestVideo = "video" SecFetchDestWebidentity = "webidentity" SecFetchDestWorker = "worker" SecFetchDestXslt = "xslt" SecPurposePrefetch = "prefetch" )
const ( XFrameOptionsDENY = "DENY" XFrameOptionsSAMEORIGIN = "SAMEORIGIN" XPermittedCrossDomainPoliciesNONE = "none" XPermittedCrossDomainPoliciesMASTER_ONLY = "master-only" XPermittedCrossDomainPoliciesBY_CONTENT_TYPE = "by-content-type" XPermittedCrossDomainPoliciesBY_FTP_FILENAME = "by-ftp-filename" XPermittedCrossDomainPoliciesALL = "all" XPermittedCrossDomainPoliciesNONE_THIS_RESPONSE = "none-this-response" TransferEncodingChunked = "chunked" TransferEncodingCompress = "compress" TransferEncodingDeflate = "deflate" TransferEncodingGzip = "gzip" )
const ( ValidationCodeTooFewItems = "too_few_items" ValidationCodeTooManyItems = "too_many_items" ValidationCodeRequired = "required" ValidationCodeTooShort = "too_short" ValidationCodeTooLong = "too_long" ValidationCodeInvalid = "invalid" )
const (
DefaultMaxMultipartMemory = 64 << 20
)
Variables ¶
var (
ErrNoBody = errors.New("no requestbody")
)
Functions ¶
func ContentDispositionAttachment ¶ added in v0.6.0
ContentDispositionAttachment returns the value of the Content-Disposition header for an attachment.
func ContentDispositionInline ¶ added in v0.6.0
ContentDispositionInline returns the value of the Content-Disposition header for an inline file.
func Validate ¶ added in v0.2.0
func Validate(v *ValidationError) error
Validate converts a ValidationError to a standard error. If the ValidationError is nil, it returns nil.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the context of an HTTP request.
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request, conf *contextConfig) *Context
NewContext creates a new Context with the given http.ResponseWriter and http.Request.
func (*Context) AcceptEncoding ¶
AcceptEncoding returns the value of the Accept-Encoding header.
func (*Context) AcceptLanguage ¶
AcceptLanguage returns the value of the Accept-Language header.
func (*Context) AccessControlRequestHeaders ¶
AccessControlRequestHeaders returns the value of the Access-Control-Request-Headers header.
func (*Context) AccessControlRequestMethod ¶
AccessControlRequestMethod returns the value of the Access-Control-Request-Method header.
func (*Context) Authorization ¶
Authorization returns the value of the Authorization header.
func (*Context) BindJson ¶ added in v0.6.0
BindJson tries to bind a json payload. Returns a response if the binding was unsuccessful
func (*Context) BindJsonOptional ¶ added in v0.6.0
BindJsonOptional tries to bind a json payload. Returns a response if the binding was unsuccessful. If the request body is empty, it returns false and nil. If the request body is not empty, it returns true and nil if the binding was successful.
func (*Context) CacheControl ¶
CacheControl returns the value of the Cache-Control header.
func (*Context) ClientIP ¶
ClientIP returns the client IP address from the request. When proxies are trusted, the address is resolved from proxy headers like X-Forwarded-For. Otherwise, the direct remote address is used.
func (*Context) ConditionalIfMatch ¶
ConditionalIfMatch makes the request conditional. Returns a response when the precondition fails.
func (*Context) ConditionalIfModifiedSince ¶
ConditionalIfModifiedSince makes the request conditional. Returns a response when the precondition fails.
func (*Context) ConditionalIfNoneMatch ¶
ConditionalIfNoneMatch makes the request conditional. Returns a response when the precondition fails.
func (*Context) ConditionalIfUnmodifiedSince ¶ added in v0.5.0
ConditionalIfUnmodifiedSince makes the request conditional. Returns a response when the precondition fails.
func (*Context) Connection ¶
Connection returns the value of the Connection header.
func (*Context) ContentDisposition ¶
ContentDisposition returns the value of the Content-Disposition header.
func (*Context) ContentEncoding ¶
ContentEncoding returns the value of the Content-Encoding header.
func (*Context) ContentLanguage ¶
ContentLanguage returns the value of the Content-Language header.
func (*Context) ContentLength ¶
ContentLength returns the value of the Content-Length header.
func (*Context) ContentLocation ¶
ContentLocation returns the value of the Content-Location header.
func (*Context) ContentType ¶
ContentType returns the value of the Content-Type header.
func (*Context) Cookie ¶
Cookie returns the named cookie provided in the request or ErrNoCookie if not found. And return the named cookie is unescaped. If multiple cookies match the given name, only one cookie will be returned.
func (*Context) Done ¶
func (c *Context) Done() <-chan struct{}
Done invokes Done on the underlying request context.
func (*Context) FormValues ¶
FormValues returns the values from a POST urlencoded form or multipart form
func (*Context) GetRawData ¶
GetRawData reads the request body and returns the raw data. Returns ErrNoBody if the request body is nil.
func (*Context) HxCurrentUrl ¶
HxCurrentUrl returns the current URL from the HX-Current-URL header.
func (*Context) HxHistoryRestoreRequest ¶
HxHistoryRestoreRequest returns true if this request is for history restoration.
func (*Context) HxTriggerName ¶
HxTriggerName returns the name of the triggered element if it exists.
func (*Context) IfModifiedSince ¶
IfModifiedSince returns the value of the If-Modified-Since header.
func (*Context) IfNoneMatch ¶
IfNoneMatch returns the value of the If-None-Match header.
func (*Context) IfUnmodifiedSince ¶
IfUnmodifiedSince returns the value of the If-Unmodified-Since header.
func (*Context) IntQueryOrDefault ¶
IntQueryOrDefault returns the value of the specified query parameter from the request or the default value if the parameter is not present.
func (*Context) MaxForwards ¶
MaxForwards returns the value of the Max-Forwards header.
func (*Context) PathValue ¶
PathValue returns the value of the specified path parameter from the request.
func (*Context) ProxyAuthorization ¶
ProxyAuthorization returns the value of the Proxy-Authorization header.
func (*Context) QueryArray ¶ added in v0.6.0
QueryArray returns the values of the specified query parameter from the request.
func (*Context) SecFetchDest ¶
SecFetchDest returns the value of the Sec-Fetch-Dest header.
func (*Context) SecFetchMode ¶
SecFetchMode returns the value of the Sec-Fetch-Mode header.
func (*Context) SecFetchSite ¶
SecFetchSite returns the value of the Sec-Fetch-Site header.
func (*Context) SecFetchUser ¶
SecFetchUser returns the value of the Sec-Fetch-User header.
func (*Context) SecPurpose ¶
SecPurpose returns the value of the Sec-Purpose header.
func (*Context) ServiceWorker ¶
ServiceWorker returns the value of the Service-Worker header.
func (*Context) ServiceWorkerNavigationPreload ¶
ServiceWorkerNavigationPreload returns the value of the Service-Worker-Navigation-Preload header.
func (*Context) StringQuery ¶
StringQuery returns the value of the specified query parameter from the request.
func (*Context) StringQueryOrDefault ¶
StringQueryOrDefault returns the value of the specified query parameter from the request or the default value if the parameter is not present.
func (*Context) TransferEncoding ¶
TransferEncoding returns the value of the Transfer-Encoding header.
func (*Context) UpgradeInsecureRequests ¶
UpgradeInsecureRequests returns the value of the Upgrade-Insecure-Requests header.
type ErrorDto ¶
type ErrorDto struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
ErrorDto represents an error response with a code and message.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) ANY ¶ added in v0.5.0
func (g *Group) ANY(path string, handler Handler, middleware ...Middleware)
ANY adds a new route for all methods with the given path, handler, and middleware.
func (*Group) DELETE ¶
func (g *Group) DELETE(path string, handler Handler, middleware ...Middleware)
DELETE adds a new route for the DELETE method with the given path, handler, and middleware.
func (*Group) GET ¶
func (g *Group) GET(path string, handler Handler, middleware ...Middleware)
GET adds a new route for the GET method with the given path, handler, and middleware.
func (*Group) Group ¶
func (g *Group) Group(path string, middleware ...Middleware) *Group
Group creates a new Group with the given path.
func (*Group) HEAD ¶
func (g *Group) HEAD(path string, handler Handler, middleware ...Middleware)
HEAD adds a new route for the HEAD method with the given path, handler, and middleware.
func (*Group) OPTIONS ¶
func (g *Group) OPTIONS(path string, handler Handler, middleware ...Middleware)
OPTIONS adds a new route for the OPTIONS method with the given path, handler, and middleware.
func (*Group) PATCH ¶ added in v0.5.0
func (g *Group) PATCH(path string, handler Handler, middleware ...Middleware)
PATCH adds a new route for the PATCH method with the given path, handler, and middleware.
type IPResolver ¶
func NewIPResolver ¶
func NewIPResolver(remoteIPHeaders []string, trustRemoteIdHeaders bool) *IPResolver
type Middleware ¶
Middleware represents a function that processes an HTTP request and returns a Response.
func LoggingMiddleware ¶
func LoggingMiddleware() Middleware
LoggingMiddleware logs the request and response status.
type Response ¶
type Response struct {
StatusCode int
// contains filtered or unexported fields
}
Response represents an HTTP response that can be customized with status codes, headers, and body content. It provides a fluent interface for building responses with various common HTTP status codes and payloads.
func Respond ¶
func Respond() *Response
Respond creates a new Response with default status code 200 OK and empty headers.
func (*Response) AcceptEncoding ¶
AcceptEncoding sets the "Accept-Encoding" header in the response.
func (*Response) AcceptPatch ¶
AcceptPatch sets the "Accept-Patch" header in the response.
func (*Response) AcceptPost ¶
AcceptPost sets the "Accept-Post" header in the response.
func (*Response) AcceptRanges ¶
AcceptRanges sets the "Accept-Ranges" header in the response.
func (*Response) AccessControlAllowCredentials ¶
AccessControlAllowCredentials sets the "Access-Control-Allow-Credentials" header in the response.
func (*Response) AccessControlAllowHeaders ¶
AccessControlAllowHeaders sets the "Access-Control-Allow-Headers" header in the response.
func (*Response) AccessControlAllowMethods ¶
AccessControlAllowMethods sets the "Access-Control-Allow-Methods" header in the response.
func (*Response) AccessControlAllowOrigin ¶
AccessControlAllowOrigin sets the "Access-Control-Allow-Origin" header in the response.
func (*Response) AccessControlExposeHeaders ¶
AccessControlExposeHeaders sets the "Access-Control-Expose-Headers" header in the response.
func (*Response) AccessControlMaxAge ¶
AccessControlMaxAge sets the "Access-Control-Max-Age" header in the response.
func (*Response) AfterWrite ¶
AfterWrite adds a function to be called after the response is written.
func (*Response) BadRequest ¶
BadRequest sets the HTTP status code to 400 Bad Request and optionally sets the response body.
func (*Response) Body ¶
Body sets the response body to the provided data and sets the Content-Type header.
func (*Response) BodyReader ¶ added in v0.6.0
BodyReader creates the response body from a reader.
func (*Response) CacheControl ¶
CacheControl sets the "Cache-Control" header in the response.
func (*Response) ClearSiteData ¶
ClearSiteData sets the "Clear-Site-Data" header in the response.
func (*Response) Conflict ¶
Conflict sets the HTTP status code to 409 Conflict and optionally sets the response body.
func (*Response) Connection ¶
Connection sets the "Connection" header in the response.
func (*Response) ContentDisposition ¶
ContentDisposition sets the "Content-Disposition" header in the response.
Use srv.ContentDispositionAttachment and srv.ContentDispositionInline to create the appropriate values.
func (*Response) ContentEncoding ¶
ContentEncoding sets the "Content-Encoding" header in the response.
func (*Response) ContentLanguage ¶
ContentLanguage sets the "Content-Language" header in the response.
func (*Response) ContentLength ¶
ContentLength sets the "Content-Length" header in the response.
func (*Response) ContentLocation ¶
ContentLocation sets the "Content-Location" header in the response.
func (*Response) ContentRange ¶
ContentRange sets the "Content-Range" header in the response.
func (*Response) ContentSecurityPolicy ¶
ContentSecurityPolicy sets the "Content-Security-Policy" header in the response.
func (*Response) ContentSecurityPolicyReportOnly ¶
ContentSecurityPolicyReportOnly sets the "Content-Security-Policy-Report-Only" header in the response.
func (*Response) ContentType ¶
ContentType sets the "Content-Type" header in the response.
func (*Response) Cookie ¶
func (r *Response) Cookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool) *Response
Cookie adds a Set-Cookie header to the ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
func (*Response) CookieRaw ¶
CookieRaw adds a Set-Cookie header to the ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
func (*Response) Created ¶
Created sets the HTTP status code to 201 Created and optionally sets the response body.
func (*Response) CrossOriginEmbedderPolicy ¶
CrossOriginEmbedderPolicy sets the "Cross-Origin-Embedder-Policy" header in the response.
func (*Response) CrossOriginOpenerPolicy ¶
CrossOriginOpenerPolicy sets the "Cross-Origin-Opener-Policy" header in the response.
func (*Response) CrossOriginResourcePolicy ¶
CrossOriginResourcePolicy sets the "Cross-Origin-Resource-Policy" header in the response.
func (*Response) ETag ¶
ETag sets the "ETag" header in the response. The etag value will be automatically wrapped in quotes.
func (*Response) Error ¶
Error sets the HTTP status code to 500 Internal Server Error and sets the response body to an ErrorDto. If err is nil, the error message will be empty. Otherwise, the error message will be set to err.Error().
func (*Response) Expires ¶
Expires sets the "Expires" header in the response. The time will be automatically converted to UTC and formatted according to RFC 7231.
func (*Response) Forbidden ¶
Forbidden sets the HTTP status code to 403 Forbidden and optionally sets the response body.
func (*Response) Html ¶
Html sets the response body to an HTML string. The Content-Type header is automatically set to "text/html;charset=UTF-8".
func (*Response) HxLocation ¶
HxLocation sets the HX-Location header.
func (*Response) HxRedirect ¶
HXRedirect sets the HX-Redirect header.
func (*Response) HxReplaceUrl ¶
HxReplaceUrl sets the HX-Replace-Url header.
func (*Response) HxReselect ¶
HxReselect sets the HX-Reselect header.
func (*Response) HxRetarget ¶
HxRetarget sets the HX-Retarget header.
func (*Response) HxTriggerAfterSettle ¶
HxTriggerAfterSettle sets the HX-Trigger-After-Settle header.
func (*Response) HxTriggerAfterSwap ¶
HxTriggerAfterSwap sets the HX-Trigger-After-Swap header.
func (*Response) InternalServerError ¶
func (*Response) Json ¶
Json sets the response body to a JSON-encoded representation of the provided data. The Content-Type header is automatically set to "application/json;charset=UTF-8".
func (*Response) LastModified ¶
LastModified sets the "Last-Modified" header in the response. The time will be automatically converted to UTC and formatted according to RFC 7231.
func (*Response) MethodNotAllowed ¶
MethodNotAllowed sets the HTTP status code to 405 Method Not Allowed and optionally sets the response body.
func (*Response) MovedPermanently ¶
MovedPermanently sets the HTTP status code to 301 Moved Permanently and sets the Location header.
func (*Response) NoVarySearch ¶
NoVarySearch sets the "No-Vary-Search" header in the response.
func (*Response) NotAcceptable ¶
NotAcceptable sets the HTTP status code to 406 Not Acceptable and optionally sets the response body.
func (*Response) NotFound ¶
NotFound sets the HTTP status code to 404 Not Found and optionally sets the response body.
func (*Response) NotModified ¶
NotModified sets the HTTP status code to 304 Not Modified.
func (*Response) PreconditionFailed ¶
PreconditionFailed sets the HTTP status code to 412 Precondition Failed.
func (*Response) PreferenceApplied ¶
PreferenceApplied sets the "Preference-Applied" header in the response.
func (*Response) ProxyAuthRequired ¶
ProxyAuthRequired sets the HTTP status code to 407 Proxy Authentication Required.
func (*Response) ProxyAuthenticate ¶
ProxyAuthenticate sets the "Proxy-Authenticate" header in the response.
func (*Response) ReferrerPolicy ¶
ReferrerPolicy sets the "Referrer-Policy" header in the response.
func (*Response) ReportingEndpoints ¶
ReportingEndpoints sets the "Reporting-Endpoints" header in the response.
func (*Response) RetryAfterDate ¶
RetryAfterDate sets the "Retry-After" header in the response.
func (*Response) RetryAfterSeconds ¶
RetryAfterSeconds sets the "Retry-After" header in the response.
func (*Response) ServerTiming ¶
ServerTiming sets the "Server-Timing" header in the response.
func (*Response) ServiceWorkerAllowed ¶
ServiceWorkerAllowed sets the "Service-Worker-Allowed" header in the response.
func (*Response) StrictTransportSecurity ¶
StrictTransportSecurity sets the "Strict-Transport-Security" header in the response.
func (*Response) Text ¶
Text sets the response body to a plain text string. The Content-Type header is automatically set to "text/plain;charset=UTF-8".
func (*Response) TimingAllowOrigin ¶
TimingAllowOrigin sets the "Timing-Allow-Origin" header in the response.
func (*Response) TransferEncoding ¶
TransferEncoding sets the "Transfer-Encoding" header in the response.
func (*Response) Unauthorized ¶
Unauthorized sets the HTTP status code to 401 Unauthorized and optionally sets the response body.
func (*Response) Via ¶
Via sets the "Via" header in the response. The value will be added to the existing "Via" header.
func (*Response) Write ¶
func (r *Response) Write(w http.ResponseWriter) error
Write writes the response to the http.ResponseWriter. It sets the headers and writes the body to the writer.
func (*Response) WwwHauthenticate ¶
WwwAuthenticate sets the "WWW-Authenticate" header in the response.
func (*Response) XContentTypeOptions ¶
XContentTypeOptions sets the "X-Content-Type-Options" header in the response.
func (*Response) XFrameOptions ¶
XFrameOptions sets the "X-Frame-Options" header in the response.
func (*Response) XPermittedCrossDomainPolicies ¶
XPermittedCrossDomainPolicies sets the "X-Permitted-Cross-Domain-Policies" header in the response.
func (*Response) XPoweredBy ¶
XPoweredBy sets the "X-Powered-By" header in the response.
type Server ¶
type Server struct {
MaxMultipartMemory int64
// contains filtered or unexported fields
}
Server represents an HTTP server that can handle requests and responses.
func (*Server) ANY ¶ added in v0.5.0
func (s *Server) ANY(path string, handler Handler, middleware ...Middleware)
ANY adds a new route for all methods with the given path, handler, and middleware.
func (*Server) DELETE ¶
func (s *Server) DELETE(path string, handler Handler, middleware ...Middleware)
DELETE adds a new route for the DELETE method with the given path, handler, and middleware.
func (*Server) GET ¶
func (s *Server) GET(path string, handler Handler, middleware ...Middleware)
GET adds a new route for the GET method with the given path, handler, and middleware.
func (*Server) Group ¶
func (s *Server) Group(path string, middleware ...Middleware) *Group
Group creates a new Group with the given path.
func (*Server) HEAD ¶
func (s *Server) HEAD(path string, handler Handler, middleware ...Middleware)
HEAD adds a new route for the HEAD method with the given path, handler, and middleware.
func (*Server) Handle ¶ added in v0.6.0
Handle adds a raw http.Handler to the Server. Note that no middleware is applied to the handler.
func (*Server) HandleFunc ¶ added in v0.5.0
func (s *Server) HandleFunc(pattern string, handler http.HandlerFunc)
HandleFunc adds a raw http.HandlerFunc to the Server. It is useful for handling requests that don't fit into the standard routing patterns. Note that no middleware is applied to the handler.
func (*Server) ListenAndServe ¶
ListenAndServe starts the server and listens for incoming requests on the given address.
func (*Server) OPTIONS ¶
func (s *Server) OPTIONS(path string, handler Handler, middleware ...Middleware)
OPTIONS adds a new route for the OPTIONS method with the given path, handler, and middleware.
func (*Server) PATCH ¶ added in v0.5.0
func (s *Server) PATCH(path string, handler Handler, middleware ...Middleware)
PATCH adds a new route for the PATCH method with the given path, handler, and middleware.
func (*Server) POST ¶
func (s *Server) POST(path string, handler Handler, middleware ...Middleware)
POST adds a new route for the POST method with the given path, handler, and middleware.
func (*Server) PUT ¶
func (s *Server) PUT(path string, handler Handler, middleware ...Middleware)
PUT adds a new route for the PUT method with the given path, handler, and middleware.
func (*Server) SetMaxMultipartMemory ¶
func (*Server) SetRemoteIPHeaders ¶
func (*Server) SetTrustRemoteIdHeaders ¶
func (*Server) Use ¶
func (s *Server) Use(middleware ...Middleware) *Server
Use adds middleware to the Server.
type Validatable ¶
type Validatable interface {
// Validate validates the object and returns an error if the object is invalid.
Validate() error
}
Validatable represents an object that can be validated.
type ValidationError ¶ added in v0.2.0
type ValidationError struct {
Code string `json:"code"`
Message string `json:"message"`
Errors []Violation `json:"errors"`
}
func Require ¶ added in v0.2.0
func Require(field, code, message string, cond bool, prev *ValidationError) *ValidationError
Require validates a condition and returns a ValidationError if the condition is false. If the condition is true, it returns the previous ValidationError unchanged. This allows for chaining multiple validation checks together.
func RequireEnumValue ¶ added in v0.2.0
func RequireEnumValue[T comparable](field string, value T, allowed []T, prev *ValidationError) *ValidationError
RequireEnumValue validates that a value is in the allowed list. It returns a ValidationError with ValidationCodeInvalid if the value is not in the allowed list. If the value is in the allowed list, it returns the previous ValidationError unchanged.
func RequireEnumValueIndexed ¶ added in v0.2.0
func RequireEnumValueIndexed[T comparable](fieldFormat string, index int, value T, allowed []T, prev *ValidationError) *ValidationError
It returns a ValidationError with ValidationCodeInvalid if the value is not in the allowed list. If the value is in the allowed list, it returns the previous ValidationError unchanged.
func RequireIndexed ¶ added in v0.2.0
func RequireIndexed(fieldFormat string, index int, code string, messageFormat string, cond bool, prev *ValidationError) *ValidationError
RequireIndexed validates a condition and returns a ValidationError if the condition is false. If the condition is true, it returns the previous ValidationError unchanged. This allows for chaining multiple validation checks together. The field name is formatted using the fieldFormat string and the index. The message is formatted using the messageFormat string and the index.
func RequireMaxLength ¶ added in v0.2.0
func RequireMaxLength(field string, max int, value string, prev *ValidationError) *ValidationError
RequireMaxLength validates that a string value has at most the specified maximum length. It returns a ValidationError with ValidationCodeTooLong if the value is longer than max. If the value meets the maximum length, it returns the previous ValidationError unchanged.
func RequireMaxLengthIndexed ¶ added in v0.2.0
func RequireMaxLengthIndexed(fieldFormat string, index int, max int, value string, prev *ValidationError) *ValidationError
RequireMaxLengthIndexed validates that a string value has at most the specified maximum length. It returns a ValidationError with ValidationCodeTooLong if the value is longer than max. If the value meets the maximum length, it returns the previous ValidationError unchanged. The field name is formatted using the fieldFormat string and the index. The message is formatted using the fieldFormat string and the index.
func RequireMaxLengthSlice ¶ added in v0.2.0
func RequireMaxLengthSlice[T any](field string, max int, value []T, prev *ValidationError) *ValidationError
RequireMaxLengthSlice validates that a slice has at most the specified maximum length. It returns a ValidationError with ValidationCodeTooManyItems if the slice is longer than max. If the slice meets the maximum length, it returns the previous ValidationError unchanged.
func RequireMaxLengthSliceIndexed ¶ added in v0.2.0
func RequireMaxLengthSliceIndexed[T any](fieldFormat string, index int, max int, value []T, prev *ValidationError) *ValidationError
It returns a ValidationError with ValidationCodeTooManyItems if the slice is longer than max. If the slice meets the maximum length, it returns the previous ValidationError unchanged.
func RequireMinLength ¶ added in v0.2.0
func RequireMinLength(field string, min int, value string, prev *ValidationError) *ValidationError
RequireMinLength validates that a string value has at least the specified minimum length. It returns a ValidationError with ValidationCodeTooShort if the value is shorter than min. If the value meets the minimum length, it returns the previous ValidationError unchanged.
func RequireMinLengthIndexed ¶ added in v0.2.0
func RequireMinLengthIndexed(fieldFormat string, index int, min int, value string, prev *ValidationError) *ValidationError
RequireMinLengthIndexed validates that a string value has at least the specified minimum length. It returns a ValidationError with ValidationCodeTooShort if the value is shorter than min. If the value meets the minimum length, it returns the previous ValidationError unchanged. The field name is formatted using the fieldFormat string and the index. The message is formatted using the fieldFormat string and the index.
func RequireMinLengthSlice ¶ added in v0.2.0
func RequireMinLengthSlice[T any](field string, min int, value []T, prev *ValidationError) *ValidationError
RequireMinLengthSlice validates that a slice has at least the specified minimum length. It returns a ValidationError with ValidationCodeTooFewItems if the slice is shorter than min. If the slice meets the minimum length, it returns the previous ValidationError unchanged.
func RequireMinLengthSliceIndexed ¶ added in v0.2.0
func RequireMinLengthSliceIndexed[T any](fieldFormat string, index int, min int, value []T, prev *ValidationError) *ValidationError
RequireMinLengthSliceIndexed validates that a slice has at least the specified minimum length. It returns a ValidationError with ValidationCodeTooFewItems if the slice is shorter than min. If the slice meets the minimum length, it returns the previous ValidationError unchanged.
func RequireNotEmpty ¶ added in v0.2.0
func RequireNotEmpty(field string, value string, prev *ValidationError) *ValidationError
RequireNotEmpty validates that a string value is not empty. It returns a ValidationError with ValidationCodeRequired if the value is empty. If the value is not empty, it returns the previous ValidationError unchanged.
func RequireNotEmptyIndexed ¶ added in v0.2.0
func RequireNotEmptyIndexed(fieldFormat string, index int, value string, prev *ValidationError) *ValidationError
RequireNotEmptyIndexed validates that a string value is not empty. It returns a ValidationError with ValidationCodeRequired if the value is empty. If the value is not empty, it returns the previous ValidationError unchanged. The field name is formatted using the fieldFormat string and the index. The message is formatted using the fieldFormat string and the index.
func RequireNotEmptySlice ¶ added in v0.2.0
func RequireNotEmptySlice[T any](field string, value []T, prev *ValidationError) *ValidationError
RequireNotEmptySlice validates that a slice is not empty. It returns a ValidationError with ValidationCodeRequired if the slice is empty. If the slice is not empty, it returns the previous ValidationError unchanged.
func RequireNotEmptySliceIndexed ¶ added in v0.2.0
func RequireNotEmptySliceIndexed[T any](fieldFormat string, index int, value []T, prev *ValidationError) *ValidationError
RequireNotEmptySliceIndexed validates that a slice is not empty. It returns a ValidationError with ValidationCodeRequired if the slice is empty. If the slice is not empty, it returns the previous ValidationError unchanged.
func RequireRegex ¶ added in v0.2.0
func RequireRegex(field string, value string, pattern *regexp.Regexp, prev *ValidationError) *ValidationError
RequireRegex validates that a string value matches the specified regular expression. It returns a ValidationError with ValidationCodeInvalid if the value does not match the pattern. If the value matches the pattern, it returns the previous ValidationError unchanged.
func RequireRegexIndexed ¶ added in v0.2.0
func RequireRegexIndexed(fieldFormat string, index int, value string, pattern *regexp.Regexp, prev *ValidationError) *ValidationError
RequireRegexIndexed validates that a string value matches the specified regular expression. It returns a ValidationError with ValidationCodeInvalid if the value does not match the pattern. If the value matches the pattern, it returns the previous ValidationError unchanged.
func (*ValidationError) Error ¶ added in v0.2.0
func (e *ValidationError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01_basic_server
command
|
|
|
02_groups
command
|
|
|
03_middleware
command
|
|
|
04_path_parameters
command
|
|
|
05_query_parameters
command
|
|
|
06_validation
command
|
|
|
07_simple_spa
command
|
|
|
08_spa_dynamic_index
command
|
|
|
any
command
|
|
|
basic
command
|
|
|
conditional_requests
command
|
|
|
head
command
|
|
|
raw_handler
command
|
|
|
The proxy package is experimental.
|
The proxy package is experimental. |
|
The spa package is experimental.
|
The spa package is experimental. |