Documentation
¶
Index ¶
- Constants
- Variables
- func HandlerJSON(p Problem) http.Handler
- func HandlerText(p Problem) http.Handler
- func HandlerXML(p Problem) http.Handler
- func Middleware(h Handler) middleware.Middleware
- func Multiplexer(m multiplexer.Multiplexer, opts ...MultiplexerOption) multiplexer.Multiplexer
- func PanicMiddleware() middleware.Middleware
- type AuthScheme
- type BadGateway
- type BadRequest
- type Conflict
- type ContentTooLarge
- type ContextKey
- type ErrorTree
- type ExpectationFailed
- type FailedDependency
- type Forbidden
- type GatewayTimeout
- type Gone
- type HTTPVersionNotSupported
- type Handler
- type InsufficientStorage
- type InternalServerError
- type LengthRequired
- type Locked
- type LoopDetected
- type MethodNotAllowed
- type MisdirectedRequest
- type MultiplexerOption
- type NegotiationHeader
- type NetworkAuthenticationRequired
- type NotAcceptable
- type NotExtended
- type NotFound
- type NotImplemented
- type Option
- type PaymentRequired
- type PreconditionFailed
- type PreconditionRequired
- type Problem
- type Protocol
- type ProxyAuthRequired
- type RangeNotSatisfiable
- type RegisteredProblem
- func (p RegisteredProblem) Detail() string
- func (p RegisteredProblem) Handler(self Problem) http.Handler
- func (p RegisteredProblem) Instance() string
- func (p RegisteredProblem) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (p RegisteredProblem) Status() int
- func (p RegisteredProblem) Title() string
- func (p RegisteredProblem) Type() string
- type RequestHeaderFieldsTooLarge
- type RequestTimeout
- type RetryAfter
- type ServiceUnavailable
- type Teapot
- type Template
- type TooEarly
- type TooManyRequests
- type URITooLong
- type Unauthorized
- type UnavailableForLegalReasons
- type UnprocessableContent
- type UnsupportedMediaType
- type UpgradeRequired
- type VariantAlsoNegotiates
Constants ¶
View Source
const ( ProblemMediaTypeJSON = "application/problem+json" ProblemMediaTypeXML = "application/problem+xml" )
Variables ¶
View Source
var ( AuthSchemeBasic = AuthScheme{Title: "Basic", Type: "https://datatracker.ietf.org/doc/html/rfc7617"} AuthSchemeBearer = AuthScheme{Title: "Bearer", Type: "https://datatracker.ietf.org/doc/html/rfc6750"} AuthSchemeDigest = AuthScheme{Title: "Digest", Type: "https://datatracker.ietf.org/doc/html/rfc7616"} AuthSchemeHOBA = AuthScheme{Title: "HOBA", Type: "https://datatracker.ietf.org/doc/html/rfc7486"} AuthSchemeMutual = AuthScheme{Title: "Mutual", Type: "https://datatracker.ietf.org/doc/html/rfc8120"} AuthSchemeNegotiate = AuthScheme{Title: "Negotiate", Type: "https://datatracker.ietf.org/doc/html/rfc4599"} AuthSchemeVAPID = AuthScheme{Title: "VAPID", Type: "https://datatracker.ietf.org/doc/html/rfc8292"} AuthSchemeSCRAM = AuthScheme{Title: "SCRAM", Type: "https://datatracker.ietf.org/doc/html/rfc8292"} AuthSchemeAWS4HMACSHA256 = AuthScheme{Title: "AWS4-HMAC-SHA256", Type: "https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html"} )
View Source
var ( DefaultTypeURI = "about:blank" DefaultTemplate = template.Must(template.New("x-smalltrip-problem-template").Parse(` <!DOCTYPE html> <html> <head> <title>{{ .Status }} - {{ .Title }}</title> </head> <body> <h1>{{.Status}} - {{ .Title }}</h1> <p><code>{{ .Type }}</code></p> <p>{{ .Detail }}</p> {{if .Instance}} <p>Instance: {{ .Instance }}</p> {{end}} <code>{{printf "%#v" .}}<code> </body> <html> `)) DefaultHandler = HandlerMiddleware(HandlerBrowser(DefaultTemplate)) )
View Source
var DefaultMethods = multiplexer.DefaultMethods
Functions ¶
func HandlerJSON ¶
func HandlerText ¶
func HandlerXML ¶
func Middleware ¶
func Middleware(h Handler) middleware.Middleware
func Multiplexer ¶
func Multiplexer(m multiplexer.Multiplexer, opts ...MultiplexerOption) multiplexer.Multiplexer
func PanicMiddleware ¶
func PanicMiddleware() middleware.Middleware
Types ¶
type AuthScheme ¶
type BadGateway ¶
type BadGateway struct{ RegisteredProblem }
func NewBadGateway ¶
func NewBadGateway(opts ...Option) BadGateway
type BadRequest ¶
type BadRequest struct{ RegisteredProblem }
func NewBadRequest ¶
func NewBadRequest(detail string, opts ...Option) BadRequest
type ContentTooLarge ¶
type ContentTooLarge struct{ RegisteredProblem }
func NewContentTooLarge ¶
func NewContentTooLarge(opts ...Option) ContentTooLarge
type ContextKey ¶
type ContextKey string
var DefaultContextKey ContextKey = "x-smalltrip-problems-middleware-handler"
type ErrorTree ¶
type ExpectationFailed ¶
type ExpectationFailed struct{ RegisteredProblem }
func NewExpectationFailed ¶
func NewExpectationFailed(opts ...Option) ExpectationFailed
type FailedDependency ¶
type FailedDependency struct{ RegisteredProblem }
func NewFailedDependency ¶
func NewFailedDependency(opts ...Option) FailedDependency
type GatewayTimeout ¶
type GatewayTimeout struct{ RegisteredProblem }
func NewGatewayTimeout ¶
func NewGatewayTimeout(opts ...Option) GatewayTimeout
type HTTPVersionNotSupported ¶
type HTTPVersionNotSupported struct{ RegisteredProblem }
func NewHTTPVersionNotSupported ¶
func NewHTTPVersionNotSupported(opts ...Option) HTTPVersionNotSupported
type Handler ¶
func HandlerBrowser ¶
func HandlerContentType ¶
func HandlerMiddleware ¶
func HandlerTemplate ¶
type InsufficientStorage ¶
type InsufficientStorage struct{ RegisteredProblem }
func NewInsufficientStorage ¶
func NewInsufficientStorage(opts ...Option) InsufficientStorage
type InternalServerError ¶
type InternalServerError struct {
RegisteredProblem
Errors []ErrorTree `json:"errors" xml:"errors"`
// contains filtered or unexported fields
}
func NewInternalServerError ¶
func NewInternalServerError(err error, opts ...Option) InternalServerError
func (InternalServerError) Error ¶
func (p InternalServerError) Error() string
func (InternalServerError) ServeHTTP ¶
func (p InternalServerError) ServeHTTP(w http.ResponseWriter, r *http.Request)
type LengthRequired ¶
type LengthRequired struct{ RegisteredProblem }
func NewLengthRequired ¶
func NewLengthRequired(opts ...Option) LengthRequired
type Locked ¶
type Locked struct{ RegisteredProblem }
type LoopDetected ¶
type LoopDetected struct{ RegisteredProblem }
func NewLoopDetected ¶
func NewLoopDetected(opts ...Option) LoopDetected
type MethodNotAllowed ¶
type MethodNotAllowed struct {
RegisteredProblem
Allowed []string `json:"allowed,omitempty" xml:"allowed,omitempty"`
}
func NewMethodNotAllowed ¶
func NewMethodNotAllowed[T string | []string](allow T, opts ...Option) MethodNotAllowed
func (MethodNotAllowed) ServeHTTP ¶
func (p MethodNotAllowed) ServeHTTP(w http.ResponseWriter, r *http.Request)
type MisdirectedRequest ¶
type MisdirectedRequest struct{ RegisteredProblem }
func NewMisdirectedRequest ¶
func NewMisdirectedRequest(opts ...Option) MisdirectedRequest
type MultiplexerOption ¶
type MultiplexerOption func(*mux)
func WithMethod ¶
func WithMethod(method string) MultiplexerOption
func WithMethodList ¶
func WithMethodList(list []string) MultiplexerOption
func WithMethodNotAllowed ¶
func WithMethodNotAllowed(h http.Handler) MultiplexerOption
func WithNotFound ¶
func WithNotFound(h http.Handler) MultiplexerOption
type NegotiationHeader ¶
type NegotiationHeader string
const ( NegotiationHeaderAccept NegotiationHeader = "Accept" NegotiationHeaderAcceptEncoding NegotiationHeader = "AcceptEncoding" NegotiationHeaderAcceptLanguage NegotiationHeader = "AcceptLanguage" )
type NetworkAuthenticationRequired ¶
type NetworkAuthenticationRequired struct{ RegisteredProblem }
func NewNetworkAuthenticationRequired ¶
func NewNetworkAuthenticationRequired(opts ...Option) NetworkAuthenticationRequired
type NotAcceptable ¶
type NotAcceptable struct {
RegisteredProblem
Allowed []string `json:"allowed,omitempty" xml:"allowed,omitempty"`
}
func NewNotAcceptable ¶
func NewNotAcceptable[T string | []string](header NegotiationHeader, allow T, opts ...Option) NotAcceptable
func (NotAcceptable) ServeHTTP ¶
func (p NotAcceptable) ServeHTTP(w http.ResponseWriter, r *http.Request)
type NotExtended ¶
type NotExtended struct{ RegisteredProblem }
func NewNotExtended ¶
func NewNotExtended(opts ...Option) NotExtended
type NotImplemented ¶
type NotImplemented[T time.Time | time.Duration] struct { RegisteredProblem RetryAfter RetryAfter[T] `json:"retryAfter" xml:"retry-after"` }
func NewNotImplemented ¶
func (NotImplemented[T]) ServeHTTP ¶
func (p NotImplemented[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Option ¶
type Option func(*RegisteredProblem)
func WithDetail ¶
func WithDetailf ¶
func WithInstance ¶
func WithStatus ¶
type PaymentRequired ¶
type PaymentRequired struct{ RegisteredProblem }
func NewPaymentRequired ¶
func NewPaymentRequired(opts ...Option) PaymentRequired
type PreconditionFailed ¶
type PreconditionFailed struct{ RegisteredProblem }
func NewPreconditionFailed ¶
func NewPreconditionFailed(opts ...Option) PreconditionFailed
type PreconditionRequired ¶
type PreconditionRequired struct{ RegisteredProblem }
func NewPreconditionRequired ¶
func NewPreconditionRequired(opts ...Option) PreconditionRequired
type ProxyAuthRequired ¶
type ProxyAuthRequired struct {
RegisteredProblem
Authentication AuthScheme `json:"authentication,omitempty" xml:"authentication,omitempty"`
}
func NewProxyAuthRequired ¶
func NewProxyAuthRequired(scheme AuthScheme, opts ...Option) ProxyAuthRequired
func (ProxyAuthRequired) ServeHTTP ¶
func (p ProxyAuthRequired) ServeHTTP(w http.ResponseWriter, r *http.Request)
type RangeNotSatisfiable ¶
type RangeNotSatisfiable struct {
RegisteredProblem
Range string `json:"range" xml:"range"`
}
func NewRangeNotSatisfiable ¶
func NewRangeNotSatisfiable(unit string, contentRange int, opts ...Option) RangeNotSatisfiable
func (RangeNotSatisfiable) ServeHTTP ¶
func (p RangeNotSatisfiable) ServeHTTP(w http.ResponseWriter, r *http.Request)
type RegisteredProblem ¶
type RegisteredProblem struct {
TypeURI string `json:"type,omitempty" xml:"type,omitempty"`
TypeTitle string `json:"title,omitempty" xml:"title,omitempty"`
StatusCode int `json:"status,omitempty" xml:"status,omitempty"`
DetailMessage string `json:"detail,omitempty" xml:"detail,omitempty"`
InstanceURI string `json:"instance,omitempty" xml:"instance,omitempty"`
XMLName xml.Name `json:"-" xml:"problem"`
// contains filtered or unexported fields
}
func New ¶
func New(opts ...Option) RegisteredProblem
func NewDetailed ¶
func NewDetailed(s int, detail string, opts ...Option) RegisteredProblem
func NewStatus ¶
func NewStatus(s int, opts ...Option) RegisteredProblem
func (RegisteredProblem) Detail ¶
func (p RegisteredProblem) Detail() string
func (RegisteredProblem) Instance ¶
func (p RegisteredProblem) Instance() string
func (RegisteredProblem) ServeHTTP ¶
func (p RegisteredProblem) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (RegisteredProblem) Status ¶
func (p RegisteredProblem) Status() int
func (RegisteredProblem) Title ¶
func (p RegisteredProblem) Title() string
func (RegisteredProblem) Type ¶
func (p RegisteredProblem) Type() string
type RequestHeaderFieldsTooLarge ¶
type RequestHeaderFieldsTooLarge struct{ RegisteredProblem }
func NewRequestHeaderFieldsTooLarge ¶
func NewRequestHeaderFieldsTooLarge(opts ...Option) RequestHeaderFieldsTooLarge
type RequestTimeout ¶
type RequestTimeout struct{ RegisteredProblem }
func NewRequestTimeout ¶
func NewRequestTimeout(opts ...Option) RequestTimeout
func (RequestTimeout) ServeHTTP ¶
func (p RequestTimeout) ServeHTTP(w http.ResponseWriter, r *http.Request)
type RetryAfter ¶
func (RetryAfter[T]) MarshalText ¶
func (h RetryAfter[T]) MarshalText() ([]byte, error)
func (RetryAfter[T]) String ¶
func (h RetryAfter[T]) String() string
type ServiceUnavailable ¶
func NewServiceUnavailable ¶
func (ServiceUnavailable[T]) ServeHTTP ¶
func (p ServiceUnavailable[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Teapot ¶
type Teapot struct{ RegisteredProblem }
type TooManyRequests ¶
type TooManyRequests[T time.Time | time.Duration] struct { RegisteredProblem RetryAfter RetryAfter[T] `json:"retryAfter" xml:"retry-after"` }
func NewTooManyRequests ¶
func (TooManyRequests[T]) ServeHTTP ¶
func (p TooManyRequests[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)
type URITooLong ¶
type URITooLong struct{ RegisteredProblem }
func NewURITooLong ¶
func NewURITooLong(opts ...Option) URITooLong
type Unauthorized ¶
type Unauthorized struct {
}
func NewUnauthorized ¶
func NewUnauthorized(scheme AuthScheme, opts ...Option) Unauthorized
func (Unauthorized) ServeHTTP ¶
func (p Unauthorized) ServeHTTP(w http.ResponseWriter, r *http.Request)
type UnavailableForLegalReasons ¶
func NewUnavailableForLegalReasons ¶
func NewUnavailableForLegalReasons(opts ...Option) UnavailableForLegalReasons
type UnprocessableContent ¶
type UnprocessableContent struct{ RegisteredProblem }
func NewUnprocessableContent ¶
func NewUnprocessableContent(opts ...Option) UnprocessableContent
type UnsupportedMediaType ¶
type UnsupportedMediaType struct{ RegisteredProblem }
func NewUnsupportedMediaType ¶
func NewUnsupportedMediaType(opts ...Option) UnsupportedMediaType
type UpgradeRequired ¶
type UpgradeRequired struct {
RegisteredProblem
Protocol Protocol `json:"protocol" xml:"protocol"`
}
func NewUpgradeRequired ¶
func NewUpgradeRequired(protocol Protocol, opts ...Option) UpgradeRequired
func (UpgradeRequired) ServeHTTP ¶
func (p UpgradeRequired) ServeHTTP(w http.ResponseWriter, r *http.Request)
type VariantAlsoNegotiates ¶
type VariantAlsoNegotiates struct{ RegisteredProblem }
func NewVariantAlsoNegotiates ¶
func NewVariantAlsoNegotiates(opts ...Option) VariantAlsoNegotiates
Click to show internal directories.
Click to hide internal directories.