problem: github.com/mschneider82/problem Index | Files

package problem

import "github.com/mschneider82/problem"

Index

Package Files

problem.go

Constants

const (
    // ContentTypeJSON https://tools.ietf.org/html/rfc7807#section-6.1
    ContentTypeJSON = "application/problem+json"
    // ContentTypeXML https://tools.ietf.org/html/rfc7807#section-6.2
    ContentTypeXML = "application/problem+xml"
)

type Option Uses

type Option interface {
    // contains filtered or unexported methods
}

An Option configures a Problem using the functional options paradigm popularized by Rob Pike.

func Custom Uses

func Custom(key string, value interface{}) Option

Custom sets a custom key value

func Detail Uses

func Detail(detail string) Option

Detail A human readable explanation specific to this occurrence of the problem.

func Instance Uses

func Instance(uri string) Option

Instance an absolute URI that identifies the specific occurrence of the problem.

func Status Uses

func Status(status int) Option

Status sets the HTTP status code generated by the origin server for this occurrence of the problem.

func Title Uses

func Title(title string) Option

Title sets a title that appropriately describes it (think short) Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable

func Type Uses

func Type(uri string) Option

Type sets the type URI (typically, with the "http" or "https" scheme) that identifies the problem type. When dereferenced, it SHOULD provide human-readable documentation for the problem type

func Wrap Uses

func Wrap(err error) Option

Wrap an error to the Problem

type Problem Uses

type Problem struct {
    // contains filtered or unexported fields
}

func New Uses

func New(opts ...Option) *Problem

New generates a new Problem

func (*Problem) Append Uses

func (p *Problem) Append(opts ...Option) *Problem

Append an Option to a existing Problem

func (Problem) Error Uses

func (p Problem) Error() string

Error implements the error interface, so a Problem can be used as an error

func (Problem) Is Uses

func (p Problem) Is(err error) bool

Is compares Problem.Error() with err.Error()

func (Problem) JSON Uses

func (p Problem) JSON() []byte

JSON returns the Problem as json bytes

func (Problem) JSONString Uses

func (p Problem) JSONString() string

JSONString returns the Problem as json string

func (Problem) MarshalJSON Uses

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

MarshalJSON implements the json.Marshaler interface

func (Problem) MarshalXML Uses

func (p Problem) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface

func (Problem) UnmarshalJSON Uses

func (p Problem) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

func (*Problem) UnmarshalXML Uses

func (p *Problem) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface

func (Problem) Unwrap Uses

func (p Problem) Unwrap() error

Unwrap returns the result of calling the Unwrap method on err, if err implements Unwrap. Otherwise, Unwrap returns nil.

func (Problem) WriteTo Uses

func (p Problem) WriteTo(w http.ResponseWriter) (int, error)

WriteTo writes the JSON Problem to a http Response Writer using the correct Content-Type and the problem's http statuscode

func (Problem) WriteXMLTo Uses

func (p Problem) WriteXMLTo(w http.ResponseWriter) (int, error)

WriteXMLTo writes the XML Problem to a http Response Writer using the correct Content-Type and the problem's http statuscode

func (Problem) XML Uses

func (p Problem) XML() []byte

XML returns the Problem as json bytes

func (Problem) XMLString Uses

func (p Problem) XMLString() string

XMLString returns the Problem as xml

Package problem imports 5 packages (graph). Updated 2019-10-19. Refresh now. Tools for package owners.