problems

package
v0.0.0-...-e7c744b Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProblemMediaType is the default media type for a DefaultProblem response
	ProblemMediaType = problems.ProblemMediaType

	// ProblemMediaTypeXML is the XML variant on the DefaultProblem Media type
	ProblemMediaTypeXML = problems.ProblemMediaTypeXML

	// DefaultURL is the default url to use for problem types
	DefaultURL = problems.DefaultURL
)

Variables

This section is empty.

Functions

func ProblemHandler

func ProblemHandler(p Problem) http.HandlerFunc

ProblemHandler returns an http.HandlerFunc which writes a provided problem to an http.ResponseWriter as JSON

func StatusProblemHandler

func StatusProblemHandler(p StatusProblem) http.HandlerFunc

StatusProblemHandler returns an http.HandlerFunc which writes a provided problem to an http.ResponseWriter as JSON with the status code

func ValidateProblem

func ValidateProblem(p Problem) error

ValidateProblem ensures that the provided Problem implementation meets the Problem description requirements. Which means that the Type is a valid uri, and that the Title be a non-empty string. Should the provided Problem be in violation of either of these requirements, an error is returned.

Types

type DefaultProblem

type DefaultProblem struct {
	*problems.DefaultProblem

	// Legacy banzai error response fields
	Code    int    `json:"code"`
	Message string `json:"message"`
	Error   string `json:"error"`
}

DefaultProblem describes an RFC-7807 problem.

func NewDetailedProblem

func NewDetailedProblem(status int, details string) *DefaultProblem

NewDetailedProblem returns a problem with details and legacy banzai fields filled.

func NewStatusProblem

func NewStatusProblem(status int) *DefaultProblem

NewStatusProblem will generate a default problem for the provided HTTP status code. The Problem's Status field will be set to match the status argument, and the Title will be set to the default Go status text for that code.

type Problem

type Problem = problems.Problem

Problem is the interface describing an HTTP API problem. These "problem details" are designed to encompass a way to carry machine- readable details of errors in a HTTP response to avoid the need to define new error response formats for HTTP APIs.

type StatusProblem

type StatusProblem = problems.StatusProblem

StatusProblem is the interface describing a problem with an associated Status code.

type ValidationProblem

type ValidationProblem struct {
	*DefaultProblem

	Violations []string `json:"violations"`
}

ValidationProblem describes an RFC-7807 problem.

func NewValidationProblem

func NewValidationProblem(details string, violations []string) *ValidationProblem

NewValidationProblem returns a problem with details and validation errors.

Jump to

Keyboard shortcuts

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