Help us shape the future of Go! Take the 2026 Go Developer Survey

problem

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package problem implements RFC 9457 Problem Details for HTTP APIs.

Index

Constants

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

ContentType is the standard RFC 9457 media type.

Variables

This section is empty.

Functions

func Write added in v0.2.0

func Write(w http.ResponseWriter, p Problem)

Write serializes the Problem as an application/problem+json HTTP response.

Types

type InvalidParam

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

InvalidParam details a single schema constraint violation for 422 Unprocessable Entity responses.

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"`
	InvalidParams []InvalidParam `json:"invalid_params,omitempty"`
	Extensions    map[string]any `json:"-"`
}

Problem represents an RFC 9457 compliant error payload.

func New

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

New creates a Problem using the standard HTTP status code and title.

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 extension fields and invalid_params into the root JSON object, automatically providing standard RFC 9457 title and type values if omitted.

Jump to

Keyboard shortcuts

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