Documentation
¶
Index ¶
- Constants
- Variables
- func ClientIP(r *http.Request) string
- func NewErrInvalidPathParam(paramName string) error
- func NewErrInvalidQueryParam(paramName string) error
- func ParsePathParamAs[T any](r *http.Request, name string) (T, error)
- func ParsePathParamOrAs[T any](r *http.Request, name string, defaultValue T) (T, error)
- func ParseQueryParamAs[T any](r *http.Request, name string) (T, error)
- func ParseQueryParamOrAs[T any](r *http.Request, name string, defaultValue T) (T, error)
- func ParseValueAs[T any](value string) (T, error)
- type Binder
- type BinderOption
- type EmptyResponse
- type ErrConverter
- type ErrInvalidParam
- type ErrResponse
- type Responder
- func (r *Responder) Created(w http.ResponseWriter, i any)
- func (r *Responder) EmptyOK(w http.ResponseWriter)
- func (r *Responder) Error(w http.ResponseWriter, err error)
- func (r *Responder) InternalServerError(w http.ResponseWriter)
- func (r *Responder) JSON(w http.ResponseWriter, statusCode int, i any)
- func (r *Responder) NoContent(w http.ResponseWriter)
- func (r *Responder) OK(w http.ResponseWriter, i any)
- func (r *Responder) Redirect(w http.ResponseWriter, code int, url string)
- type ResponderOption
Constants ¶
View Source
const ( HeaderContentType = "Content-Type" HeaderContentLength = "Content-Length" HeaderContentEncoding = "Content-Encoding" HeaderAuthorization = "Authorization" HeaderOrigin = "Origin" HeaderUserAgent = "User-Agent" HeaderAccept = "Accept" HeaderAcceptLanguage = "Accept-Language" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderLocation = "Location" HeaderReferer = "Referer" HeaderHost = "Host" HeaderCacheControl = "Cache-Control" HeaderETag = "ETag" HeaderLastModified = "Last-Modified" HeaderIfNoneMatch = "If-None-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderVary = "Vary" HeaderCORSAllowOrigin = "Access-Control-Allow-Origin" HeaderCORSAllowMethods = "Access-Control-Allow-Methods" HeaderCORSAllowHeaders = "Access-Control-Allow-Headers" HeaderCORSExposeHeaders = "Access-Control-Expose-Headers" HeaderCORSMaxAge = "Access-Control-Max-Age" HeaderCORSAllowCredentials = "Access-Control-Allow-Credentials" HeaderCORSRequestMethod = "Access-Control-Request-Method" HeaderCORSRequestHeaders = "Access-Control-Request-Headers" HeaderXRequestID = "X-Request-ID" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedHost = "X-Forwarded-Host" )
View Source
const ( ContentTypeJSON = "application/json; charset=utf-8" ContentTypeText = "text/plain; charset=utf-8" ContentTypeHTML = "text/html; charset=utf-8" ContentTypeFormData = "application/x-www-form-urlencoded" ContentTypeMultipart = "multipart/form-data" ContentTypeOctetStream = "application/octet-stream" )
Variables ¶
View Source
var ( ErrBodyTooLarge = errors.New("request body too large") ErrBodyInvalid = errors.New("invalid json") )
Functions ¶
func NewErrInvalidPathParam ¶
func NewErrInvalidQueryParam ¶
func ParsePathParamOrAs ¶
func ParseQueryParamOrAs ¶
func ParseValueAs ¶
Types ¶
type Binder ¶
type Binder struct {
// contains filtered or unexported fields
}
func NewBinder ¶
func NewBinder(opts ...BinderOption) *Binder
type BinderOption ¶
type BinderOption func(b *Binder)
func WithBodyMaxSize ¶
func WithBodyMaxSize(maxBodySize int64) BinderOption
type EmptyResponse ¶
type EmptyResponse struct{}
type ErrInvalidParam ¶
func (*ErrInvalidParam) Error ¶
func (e *ErrInvalidParam) Error() string
type ErrResponse ¶
type ErrResponse struct {
Message string `json:"message,omitempty"`
}
type Responder ¶
type Responder struct {
// contains filtered or unexported fields
}
func NewResponder ¶
func NewResponder(opts ...ResponderOption) *Responder
func (*Responder) EmptyOK ¶
func (r *Responder) EmptyOK(w http.ResponseWriter)
func (*Responder) InternalServerError ¶
func (r *Responder) InternalServerError(w http.ResponseWriter)
func (*Responder) NoContent ¶
func (r *Responder) NoContent(w http.ResponseWriter)
type ResponderOption ¶
type ResponderOption func(r *Responder)
func WithErrConverter ¶
func WithErrConverter(errConverter ErrConverter) ResponderOption
func WithLogger ¶
func WithLogger(log *slog.Logger) ResponderOption
Click to show internal directories.
Click to hide internal directories.