Documentation
¶
Index ¶
- Constants
- type Problem
- func (problem Problem) Additional(key string) (any, bool)
- func (problem Problem) Defaulted(request *http.Request) Problem
- func (problem Problem) Error() string
- func (problem Problem) Errors() []error
- func (problem Problem) HTTPStatus() int
- func (problem Problem) MarshalJSON() ([]byte, error)
- func (problem Problem) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (problem Problem) ServeHTTPDev(w http.ResponseWriter, r *http.Request)
- func (problem *Problem) UnmarshalJSON(data []byte) error
- func (problem Problem) Unwrap() error
- func (problem Problem) With(key string, value any) Problem
- func (problem Problem) WithError(err error) Problem
- func (problem Problem) WithStackTrace() Problem
- func (problem Problem) Without(key string) Problem
- func (problem Problem) WithoutError() Problem
- func (problem Problem) WithoutStackTrace() Problem
Constants ¶
const StackTraceKey = "stack_trace"
Determines the key that's used to store the traces in a Problem.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Problem ¶
type Problem struct {
// Type member is a JSON string containing a URI reference
// that identifies the problem type.
//
// Consumers MUST use the Type URI (after resolution,
// if necessary) as the problem type's primary identifier.
//
// When this member is not present, its value is assumed
// to be "about:blank".
Type string
// Title member is a string containing a short,
// human-readable summary of the problem type.
//
// It SHOULD NOT change from occurrence to occurrence of
// the problem, except for localization (e.g., using proactive
// content negotiation.
//
// The Title string is advisory and is included only for users
// who are unaware of and cannot discover the semantics of the
// type URI (e.g., during offline log analysis).
Title string
// Detail member is a JSON string containing a human-readable
// explanation specific to this occurrence of the problem.
//
// The Detail string, if present, ought to focus on helping
// the client correct the problem, rather than giving debugging information.
//
// Consumers SHOULD NOT parse the Detail member for information.
//
// Extensions are more suitable and less error-prone ways to obtain
// such information.
Detail string
// The Status member is a JSON number indicating the HTTP status
// code generated by the origin server for this occurrence of the problem.
//
// The "status" member, if present, is only advisory; it conveys the HTTP
// status code used for the convenience of the consumer.
//
// Generators MUST use the same status code in the actual HTTP response,
// to assure that generic HTTP software that does not understand this format
// still behaves correctly.
//
// Consumers can use the status member to determine what the original status
// code used by the generator was when it has been changed
// (e.g., by an intermediary or cache) and when a message's content is
// persisted without HTTP information. Generic HTTP software will still
// use the HTTP status code.
Status int
// The "instance" member is a JSON string containing a URI reference that
// identifies the specific occurrence of the problem.
//
// When the "instance" URI is dereferenceable, the problem details object
// can be fetched from it. It might also return information about the problem
// occurrence in other formats through use of proactive content negotiation.
//
// When the "instance" URI is not dereferenceable, it serves as a unique identifier
// for the problem occurrence that may be of significance to the server but is
// opaque to the client.
//
// When "instance" contains a relative URI, it is resolved relative to the document's
// base URI. However, using relative URIs can cause confusion, and they might not
// be handled correctly by all implementations.
//
// For example, if the two resources "https://api.example.org/foo/bar/123"
// and "https://api.example.org/widget/456" both respond with an "instance" equal
// to the relative URI reference "example-instance", when resolved they will
// identify different resources ("https://api.example.org/foo/bar/example-instance"
// and "https://api.example.org/widget/example-instance", respectively).
//
// As a result, it is RECOMMENDED that absolute URIs be used in "instance" when possible,
// and that when relative URIs are used, they include the full path (e.g., "/instances/123").
Instance string
// contains filtered or unexported fields
}
Problem represents a problem details for HTTP APIs. See https://datatracker.ietf.org/doc/html/rfc9457 for more information.
func NewProblem ¶
NewProblem creates a new Problem from the given error and status code.
func (Problem) Additional ¶
Additional returns the additional value of the given key.
Use Problem.With to add additional values. Use Problem.Without to remove additional values.
func (Problem) Defaulted ¶
Defaulted returns a Problem that is defaulted using the given request and the current instance.
func (Problem) Errors ¶
Errors returns all the strack-trace of errors that are bound to this particular Problem.
func (Problem) HTTPStatus ¶ added in v0.2.0
func (Problem) MarshalJSON ¶
MarshalJSON replaces the default JSON encoding behaviour.
func (Problem) ServeHTTPDev ¶
func (problem Problem) ServeHTTPDev(w http.ResponseWriter, r *http.Request)
func (*Problem) UnmarshalJSON ¶
UnmarshalJSON replaces the default JSON decoding behaviour.
func (Problem) Unwrap ¶
Unwrap is used to get the original error from the problem to use with the errors pkg.
func (Problem) WithStackTrace ¶
WithStackTrace adds the error traces to the Problem using the current problem. It's important to first setup the problem's error with either NewProblem or by using Problem.WithError before calling this method.
func (Problem) WithoutError ¶
WithoutError returns a new Problem with the error that's associated with it removed.
func (Problem) WithoutStackTrace ¶
WithoutStackTrace removes the traces from the Problem