problem

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Problem

type Problem struct {
	// Type is a URI reference [RFC3986] that identifies the
	// problem type. This specification encourages that, when
	// dereferenced, it provide human-readable documentation for the
	// problem type (e.g., using HTML [W3C.REC-html5-20141028]).  When
	// this member is not present, its value is assumed to be
	// "about:blank".
	Type string `json:"type"`
	// Title is a short, human-readable summary of the problem
	// type.  It SHOULD NOT change from occurrence to occurrence of the
	// problem, except for purposes of localization (e.g., using
	// proactive content negotiation; see [RFC7231], Section 3.4).
	Title string `json:"title"`
	// Status is the HTTP status code ([RFC7231], Section 6)
	// generated by the origin server for this occurrence of the problem.
	Status int `json:"status,omitempty"`
	// Detail is a human-readable explanation specific to this
	// occurrence of the problem.
	// If present, it ought to focus on helping the client
	// correct the problem, rather than giving debugging information.
	Detail string `json:"detail,omitempty"`
	// Instance is a URI reference that identifies the specific
	// occurrence of the problem.  It may or may not yield further
	// information if dereferenced.
	Instance string `json:"instance,omitempty"`
	// Params are request input field level errors. They communicate
	// back to client hints as to the exact problem.
	Params map[string]string `json:"params,omitempty"`
}

Problem is the struct definition of a problem details object

func BadRequest

func BadRequest(err error) *Problem

BadRequest will create a new problem for reqeust marshalling errors.

func New

func New(statusCode int, problemType, title, detail, instance string, params map[string]string) *Problem

New creates a new Problem with given info.

func NotCurrent

func NotCurrent() *Problem

NotCurrent will create a new problem for optimistic concurrency errors.

func NotFound

func NotFound() *Problem

NotFound will create a new problem for when the record is not found.

func NotPermitted

func NotPermitted(username string) *Problem

NotPermitted will create a new problem for when the user is forbidden access.

func RuleViolated

func RuleViolated(rule string) *Problem

RuleViolated will create a new problem for when a business rule is violated.

func Status

func Status(statusCode int) *Problem

Status creates a new ProblemDetails error based just on the HTTP status code.

func Unexpected

func Unexpected(err error) *Problem

Unexpected will create a new problem for unexpected errors.

func Validation

func Validation(params map[string]string) *Problem

Validation will create a new problem for when request has field validation errors.

func (*Problem) Error

func (pd *Problem) Error() string

Error implements the error interface

func (*Problem) ServeJSON

func (pd *Problem) ServeJSON(w http.ResponseWriter) error

ServeJSON will output Problem Details json to the response writer.

type ProblemConfig

type ProblemConfig struct {
	// the URI to be string formatted with default type codes
	ProblemTypeUrlFormat string
	// the function to return URI for this problem instance
	ProblemInstanceFunc func(ctx context.Context) string
}

func (ProblemConfig) Enrich

func (cfg ProblemConfig) Enrich(ctx context.Context, p *Problem)

Enrich will alter the type and instance of the problem as configured.

Jump to

Keyboard shortcuts

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