problem

package
v0.0.0-...-e3813da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

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 HandlerJSON(p Problem) http.Handler

func HandlerText

func HandlerText(p Problem) http.Handler

func HandlerXML

func HandlerXML(p Problem) http.Handler

func Middleware

func Middleware(h Handler) middleware.Middleware

func PanicMiddleware

func PanicMiddleware() middleware.Middleware

Types

type AuthScheme

type AuthScheme struct {
	Type  string `json:"type,omitempty" xml:"type,omitempty"`
	Title string `json:"title,omitempty" xml:"title,omitempty"`
}

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 Conflict

type Conflict struct{ RegisteredProblem }

func NewConflict

func NewConflict(opts ...Option) Conflict

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 ErrorTree struct {
	Detail string      `json:"detail" xml:"detail"`
	Errors []ErrorTree `json:"errors" xml:"errors"`

	XMLName xml.Name `json:"-" xml:"errors"`
	// contains filtered or unexported fields
}

func (ErrorTree) Error

func (i ErrorTree) Error() string

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 Forbidden

type Forbidden struct{ RegisteredProblem }

func NewForbidden

func NewForbidden(opts ...Option) Forbidden

type GatewayTimeout

type GatewayTimeout struct{ RegisteredProblem }

func NewGatewayTimeout

func NewGatewayTimeout(opts ...Option) GatewayTimeout

type Gone

type Gone struct{ RegisteredProblem }

func NewGone

func NewGone(opts ...Option) Gone

type HTTPVersionNotSupported

type HTTPVersionNotSupported struct{ RegisteredProblem }

func NewHTTPVersionNotSupported

func NewHTTPVersionNotSupported(opts ...Option) HTTPVersionNotSupported

type Handler

type Handler func(p Problem) http.Handler

func HandlerBrowser

func HandlerBrowser(template Template) Handler

func HandlerContentType

func HandlerContentType(handlers map[string]Handler, fallback ...Handler) Handler

func HandlerMiddleware

func HandlerMiddleware(fallback ...Handler) Handler

func HandlerTemplate

func HandlerTemplate(template Template) Handler

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 }

func NewLocked

func NewLocked(opts ...Option) Locked

TODO?: Should the response of this be different and follow WebDAV's XML format?

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 NotFound

type NotFound struct{ RegisteredProblem }

func NewNotFound

func NewNotFound(opts ...Option) NotFound

type NotImplemented

type NotImplemented[T time.Time | time.Duration] struct {
	RegisteredProblem
	RetryAfter RetryAfter[T] `json:"retryAfter" xml:"retry-after"`
}

func NewNotImplemented

func NewNotImplemented[T time.Time | time.Duration](retryAfter T, opts ...Option) NotImplemented[T]

func (NotImplemented[T]) ServeHTTP

func (p NotImplemented[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Option

type Option func(*RegisteredProblem)

func WithDetail

func WithDetail(d string) Option

func WithDetailf

func WithDetailf(f string, args ...any) Option

func WithError

func WithError(err error) Option

func WithInstance

func WithInstance(i string) Option

func WithStatus

func WithStatus(s int) Option

func WithTitle

func WithTitle(t string) Option

func WithType

func WithType(t string) Option

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 Problem

type Problem interface {
	Type() string
	Title() string
	Status() int
	Detail() string
	Instance() string

	Handler(self Problem) http.Handler

	http.Handler
}

type Protocol

type Protocol string
const (
	Http1_1 Protocol = "HTTP/1.1"
	Http2_0 Protocol = "HTTP/2.0"
	Http3_0 Protocol = "HTTP/3.0"
)

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) Handler

func (p RegisteredProblem) Handler(self Problem) http.Handler

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

type RetryAfter[T time.Time | time.Duration] struct {
	// contains filtered or unexported fields
}

func (RetryAfter[T]) MarshalText

func (h RetryAfter[T]) MarshalText() ([]byte, error)

func (RetryAfter[T]) String

func (h RetryAfter[T]) String() string

type ServiceUnavailable

type ServiceUnavailable[T time.Time | time.Duration] struct {
	RegisteredProblem
	RetryAfter RetryAfter[T] `json:"retryAfter" xml:"retry-after"`
}

func NewServiceUnavailable

func NewServiceUnavailable[T time.Time | time.Duration](retryAfter T, opts ...Option) ServiceUnavailable[T]

func (ServiceUnavailable[T]) ServeHTTP

func (p ServiceUnavailable[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Teapot

type Teapot struct{ RegisteredProblem }

func NewTeapot

func NewTeapot(opts ...Option) Teapot

type Template

type Template interface {
	Execute(w io.Writer, data any) error
}

type TooEarly

type TooEarly struct{ RegisteredProblem }

func NewTooEarly

func NewTooEarly(opts ...Option) TooEarly

type TooManyRequests

type TooManyRequests[T time.Time | time.Duration] struct {
	RegisteredProblem
	RetryAfter RetryAfter[T] `json:"retryAfter" xml:"retry-after"`
}

func NewTooManyRequests

func NewTooManyRequests[T time.Time | time.Duration](retryAfter T, opts ...Option) TooManyRequests[T]

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 {
	RegisteredProblem
	Authentication AuthScheme `json:"authentication,omitempty" xml:"authentication,omitempty"`
}

func NewUnauthorized

func NewUnauthorized(scheme AuthScheme, opts ...Option) Unauthorized

func (Unauthorized) ServeHTTP

func (p Unauthorized) ServeHTTP(w http.ResponseWriter, r *http.Request)

type UnavailableForLegalReasons

type UnavailableForLegalReasons struct{ RegisteredProblem }

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL