problem

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package problem renders errors as RFC 9457 problem details (application/problem+json), attaching the active trace ID so a failed response can be traced back to its span.

Index

Constants

View Source
const ContentType = "application/problem+json"

Variables

This section is empty.

Functions

func Status

func Status(w http.ResponseWriter, r *http.Request, status int, detail string)

Status is a convenience for writing a problem from just a status and detail.

Types

type FieldError

type FieldError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

type Problem

type Problem struct {
	Type     string       `json:"type"`
	Title    string       `json:"title"`
	Status   int          `json:"status"`
	Detail   string       `json:"detail,omitempty"`
	Instance string       `json:"instance,omitempty"`
	TraceID  string       `json:"traceId,omitempty"`
	Errors   []FieldError `json:"errors,omitempty"`
}

Problem is an RFC 9457 problem details object.

func New

func New(status int, detail string) *Problem

New builds a problem with type "about:blank" and the standard title for the status code, per RFC 9457 section 4.2.1.

func (*Problem) WithField

func (p *Problem) WithField(field, message string) *Problem

func (*Problem) WithType

func (p *Problem) WithType(uri, title string) *Problem

func (*Problem) Write

func (p *Problem) Write(w http.ResponseWriter, r *http.Request)

Write renders the problem, setting the trace ID from the request context and defaulting the instance to the request path.

Jump to

Keyboard shortcuts

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