Versions in this module Expand all Collapse all v0 v0.5.0 May 10, 2026 Changes in this version + const ContentTypeJSON + const ContentTypeJSONUTF8 + const ContentTypeXML + const ContentTypeXMLUTF8 + const DefaultCodeSeparator + const DefaultLogArgKey + const DefaultLogLevel + const DefaultTitle + const DefaultTypeURI + var DefaultGenerator = &Generator + var ErrCode = errors.New("invalid problem code") + func Is(err error) bool + func IsMatch(err error, matchers ...Matcher) bool + func Log(msg string, prob *Problem, args ...any) + func LogContext(ctx context.Context, msg string, prob *Problem, args ...any) + func Match(prob *Problem, matchers ...Matcher) bool + func Middleware(probFunc func(err error) *Problem, opts ...WriteOptions) func(http.Handler) http.Handler + func MiddlewareUsing(gen *Generator, probFunc func(err error) *Problem, opts ...WriteOptions) func(http.Handler) http.Handler + func MustValidateCode(code Code, namespace ...CodeNamespace) + func MustValidateCodeNamespace(namespace CodeNamespace) + func MustValidateCodeValue(value uint) + func UsingGenerator(parent context.Context, gen *Generator) context.Context + func ValidateCode(code Code, namespace ...CodeNamespace) error + func ValidateCodeNamespace(namespace CodeNamespace) error + func ValidateCodeValue(value uint) error + func WriteError(err error, w http.ResponseWriter, req *http.Request, ...) error + func WriteErrorJSON(err error, w http.ResponseWriter, req *http.Request, ...) error + func WriteErrorXML(err error, w http.ResponseWriter, req *http.Request, ...) error + func WriteProblem(prob *Problem, w http.ResponseWriter, req *http.Request, opts ...WriteOptions) error + func WriteProblemJSON(prob *Problem, w http.ResponseWriter, req *http.Request, opts ...WriteOptions) error + func WriteProblemXML(prob *Problem, w http.ResponseWriter, req *http.Request, opts ...WriteOptions) error + type Builder struct + Generator *Generator + func Build() *Builder + func BuildContext(ctx context.Context) *Builder + func (b *Builder) Clone() *Builder + func (b *Builder) Code(value uint, namespace CodeNamespace) *Builder + func (b *Builder) Definition(def Definition) *Builder + func (b *Builder) DefinitionType(defType Type) *Builder + func (b *Builder) Detail(detail string) *Builder + func (b *Builder) DetailKey(key any) *Builder + func (b *Builder) Detailf(format string, args ...any) *Builder + func (b *Builder) Extension(key string, value any) *Builder + func (b *Builder) Extensions(extensions Extensions) *Builder + func (b *Builder) Instance(instanceURI string) *Builder + func (b *Builder) Instancef(format string, args ...any) *Builder + func (b *Builder) LogLevel(level LogLevel) *Builder + func (b *Builder) Problem() *Problem + func (b *Builder) Reset() *Builder + func (b *Builder) Stack(flags ...Flag) *Builder + func (b *Builder) StackFramesSkipped(skipped int) *Builder + func (b *Builder) Status(status int) *Builder + func (b *Builder) String() string + func (b *Builder) Title(title string) *Builder + func (b *Builder) TitleKey(key any) *Builder + func (b *Builder) Titlef(format string, args ...any) *Builder + func (b *Builder) Type(typeURI string) *Builder + func (b *Builder) Typef(format string, args ...any) *Builder + func (b *Builder) UUID(flags ...Flag) *Builder + func (b *Builder) Wrap(err error, unwrapper ...Unwrapper) *Builder + type Code string + func BuildCode(value uint, namespace CodeNamespace) (Code, error) + func MustBuildCode(value uint, namespace CodeNamespace) Code + type CodeNamespace string + type CodeNamespaceValidator func(namespace CodeNamespace) error + func ComposeCodeNamespaceValidator(validators ...CodeNamespaceValidator) CodeNamespaceValidator + func LenCodeNamespaceValidator(min int, max ...int) CodeNamespaceValidator + func RegexpCodeNamespaceValidator(expr string) CodeNamespaceValidator + func UnicodeCodeNamespaceValidator(predicate func(r rune) bool, mapper func(r rune) rune) CodeNamespaceValidator + type Definition struct + Code Code + Detail string + DetailKey any + Extensions map[string]any + Instance string + Type Type + func (d Definition) Build() *Builder + func (d Definition) BuildContext(ctx context.Context) *Builder + func (d Definition) BuildContextUsing(ctx context.Context, gen *Generator) *Builder + func (d Definition) BuildUsing(gen *Generator) *Builder + func (d Definition) New(opts ...Option) *Problem + func (d Definition) NewContext(ctx context.Context, opts ...Option) *Problem + func (d Definition) NewContextUsing(ctx context.Context, gen *Generator, opts ...Option) *Problem + func (d Definition) NewUsing(gen *Generator, opts ...Option) *Problem + type Extensions map[string]any + func (es Extensions) MarshalXML(e *xml.Encoder, _ xml.StartElement) error + func (es Extensions) UnmarshalXML(_ *xml.Decoder, _ xml.StartElement) error + type Flag uint8 + const FlagDisable + const FlagField + const FlagLog + type Generator struct + CodeNamespaceValidator CodeNamespaceValidator + CodeSeparator rune + CodeValueLen int + ContentType string + LogArgKey string + LogLeveler LogLeveler + Logger Logger + StackFlag Flag + Translator Translator + Typer Typer + UUIDFlag Flag + UUIDGenerator UUIDGenerator + Unwrapper Unwrapper + func GetGenerator(ctx context.Context) *Generator + func (g *Generator) Build() *Builder + func (g *Generator) BuildCode(value uint, namespace CodeNamespace) (Code, error) + func (g *Generator) BuildContext(ctx context.Context) *Builder + func (g *Generator) Log(msg string, prob *Problem, args ...any) + func (g *Generator) LogContext(ctx context.Context, msg string, prob *Problem, args ...any) + func (g *Generator) MustBuildCode(value uint, namespace CodeNamespace) Code + func (g *Generator) MustParseCode(code Code, namespace ...CodeNamespace) ParsedCode + func (g *Generator) MustValidateCode(code Code, namespace ...CodeNamespace) + func (g *Generator) MustValidateCodeNamespace(namespace CodeNamespace) + func (g *Generator) MustValidateCodeValue(value uint) + func (g *Generator) New(opts ...Option) *Problem + func (g *Generator) NewContext(ctx context.Context, opts ...Option) *Problem + func (g *Generator) ParseCode(code Code, namespace ...CodeNamespace) (ParsedCode, error) + func (g *Generator) ValidateCode(code Code, namespace ...CodeNamespace) error + func (g *Generator) ValidateCodeNamespace(namespace CodeNamespace) error + func (g *Generator) ValidateCodeValue(value uint) error + func (g *Generator) WriteError(err error, w http.ResponseWriter, req *http.Request, ...) error + func (g *Generator) WriteErrorJSON(err error, w http.ResponseWriter, req *http.Request, ...) error + func (g *Generator) WriteErrorXML(err error, w http.ResponseWriter, req *http.Request, ...) error + func (g *Generator) WriteProblem(prob *Problem, w http.ResponseWriter, req *http.Request, opts ...WriteOptions) error + func (g *Generator) WriteProblemJSON(prob *Problem, w http.ResponseWriter, req *http.Request, opts ...WriteOptions) error + func (g *Generator) WriteProblemXML(prob *Problem, w http.ResponseWriter, req *http.Request, opts ...WriteOptions) error + type LogInfo struct + Level LogLevel + Stack string + UUID string + type LogLevel uint + const LogLevelDebug + const LogLevelError + const LogLevelInfo + const LogLevelWarn + type LogLeveler func(defType Type) LogLevel + type Logger func(ctx context.Context, level LogLevel, msg string, args ...any) + func DefaultLogger() Logger + func DefaultLoggerContext(handleCtx func(ctx context.Context, logger *slog.Logger) *slog.Logger) Logger + func LoggerFrom(logger *slog.Logger) Logger + func LoggerFromContext(logger *slog.Logger, ...) Logger + func NoopLogger() Logger + type Matcher func(prob *Problem) bool + func HasCode(value uint, namespace CodeNamespace, operator ...Operator) Matcher + func HasCodeNamespace(namespace CodeNamespace, operator ...Operator) Matcher + func HasCodeNamespaceUsing(gen *Generator, namespace CodeNamespace, operator ...Operator) Matcher + func HasCodeUsing(gen *Generator, value uint, namespace CodeNamespace, operator ...Operator) Matcher + func HasCodeValue(value uint, operator ...Operator) Matcher + func HasCodeValueUsing(gen *Generator, value uint, operator ...Operator) Matcher + func HasDetail(detail string, operator ...Operator) Matcher + func HasExtension(key string) Matcher + func HasExtensionWithValue(key string, valueMatcher func(value any) bool) Matcher + func HasExtensions(keys ...string) Matcher + func HasInstance(instance string, operator ...Operator) Matcher + func HasStack() Matcher + func HasStatus(status int, operator ...Operator) Matcher + func HasTitle(title string, operator ...Operator) Matcher + func HasType(typeURI string, operator ...Operator) Matcher + func HasUUID() Matcher + func Or(matchers ...Matcher) Matcher + type Operator uint8 + const OperatorEquals + const OperatorGreaterThan + const OperatorGreaterThanOrEqual + const OperatorLessThan + const OperatorLessThanOrEqual + const OperatorNotEquals + type Option func(b *Builder) + func FromDefinition(def Definition) Option + func FromType(defType Type) Option + func WithCode(value uint, namespace CodeNamespace) Option + func WithDetail(detail string) Option + func WithDetailKey(key any) Option + func WithDetailKeyOrElse(key any, detail string) Option + func WithDetailf(format string, args ...any) Option + func WithExtension(key string, value any) Option + func WithExtensions(extensions Extensions) Option + func WithInstance(instanceURI string) Option + func WithInstancef(format string, args ...any) Option + func WithLogLevel(level LogLevel) Option + func WithStack(flags ...Flag) Option + func WithStackFramesSkipped(skipped int) Option + func WithStatus(status int) Option + func WithTitle(title string) Option + func WithTitleKey(key any) Option + func WithTitleKeyOrElse(key any, title string) Option + func WithTitlef(format string, args ...any) Option + func WithType(typeURI string) Option + func WithTypef(format string, args ...any) Option + func WithUUID(flags ...Flag) Option + func Wrap(err error, unwrapper ...Unwrapper) Option + type ParsedCode struct + Code Code + Namespace CodeNamespace + Value uint + func MustParseCode(code Code, namespace ...CodeNamespace) ParsedCode + func ParseCode(code Code, namespace ...CodeNamespace) (ParsedCode, error) + type Problem struct + Code Code + Detail string + Extensions Extensions + Instance string + Stack string + Status int + Title string + Type string + UUID string + func As(err error) (*Problem, bool) + func AsMatch(err error, matchers ...Matcher) (*Problem, bool) + func AsMatchOrElse(err error, defaultProb *Problem, matchers ...Matcher) *Problem + func AsMatchOrElseGet(err error, defaultProbFunc func() *Problem, matchers ...Matcher) *Problem + func AsOrElse(err error, defaultProb *Problem) (*Problem, bool) + func AsOrElseGet(err error, defaultProbFunc func() *Problem) (*Problem, bool) + func New(opts ...Option) *Problem + func NewContext(ctx context.Context, opts ...Option) *Problem + func (p *Problem) Clone() *Problem + func (p *Problem) Error() string + func (p *Problem) Extension(key string) (value any, found bool) + func (p *Problem) LogInfo() LogInfo + func (p *Problem) LogValue() slog.Value + func (p *Problem) MarshalJSON() ([]byte, error) + func (p *Problem) MarshalXML(e *xml.Encoder, start xml.StartElement) error + func (p *Problem) String() string + func (p *Problem) UnmarshalJSON(data []byte) error + func (p *Problem) Unwrap() error + type Translator func(ctx context.Context, key any) string + func NoopTranslator() Translator + type Type struct + LogLevel LogLevel + Status int + Title string + TitleKey any + URI string + func (t Type) Build() *Builder + func (t Type) BuildContext(ctx context.Context) *Builder + func (t Type) BuildContextUsing(ctx context.Context, gen *Generator) *Builder + func (t Type) BuildUsing(gen *Generator) *Builder + func (t Type) New(opts ...Option) *Problem + func (t Type) NewContext(ctx context.Context, opts ...Option) *Problem + func (t Type) NewContextUsing(ctx context.Context, gen *Generator, opts ...Option) *Problem + func (t Type) NewUsing(gen *Generator, opts ...Option) *Problem + type Typer func(defType Type) string + type UUIDGenerator func(ctx context.Context) string + func V4UUIDGenerator() UUIDGenerator + func V4UUIDGeneratorFromReader(reader io.Reader) UUIDGenerator + func V7UUIDGenerator() UUIDGenerator + func V7UUIDGeneratorFromReader(reader io.Reader) UUIDGenerator + type Unwrapper func(err error) Problem + func FullUnwrapper() Unwrapper + func NoopUnwrapper() Unwrapper + func PropagatedFieldUnwrapper() Unwrapper + type WriteOptions struct + ContentType string + LogArgs []any + LogDisabled bool + LogMessage string + Status int