problem

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

ContentType is the standard RFC 9457 media type for Problem Details JSON payloads.

View Source
const DefaultTypePrefix = "urn:hclapi:error:"

DefaultTypePrefix is the standard URN namespace prefix for built-in problem types.

Variables

This section is empty.

Functions

func DefaultHandler

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

DefaultHandler serializes a Problem as an application/problem+json response.

func Slugify

func Slugify(title string) string

Slugify converts a title into a lowercase hyphenated slug (e.g. "Not Found" -> "not-found").

func TypeURI

func TypeURI(slug string) string

TypeURI returns a standard URN identifier for a given error slug.

Types

type Handler

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

Handler defines the contract for serializing Problem Details to an HTTP client.

type InvalidParam

type InvalidParam struct {
	Name   string `json:"name"`
	Reason string `json:"reason"`
}

InvalidParam represents a single field-level schema validation failure.

type Problem

type Problem struct {
	Type          string         `json:"type,omitempty"`
	Title         string         `json:"title"`
	Status        int            `json:"status"`
	Detail        string         `json:"detail,omitempty"`
	Instance      string         `json:"instance,omitempty"`
	Step          string         `json:"step,omitempty"`
	InvalidParams []InvalidParam `json:"invalid_params,omitempty"`
	Extensions    map[string]any `json:"-"`
}

Problem represents an RFC 9457 compliant error object.

func New

func New(status int, detail ...string) Problem

New constructs a Problem with canonical title and type URI derived from the HTTP status code.

func (Problem) Error

func (p Problem) Error() string

Error implements the standard Go error interface.

func (Problem) MarshalJSON

func (p Problem) MarshalJSON() ([]byte, error)

MarshalJSON flattens RFC 9457 extension members into the root JSON object.

Jump to

Keyboard shortcuts

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