Documentation
¶
Index ¶
- type Problem
- func (p *Problem) JSON(w http.ResponseWriter)
- func (p Problem) MarshalJSON() ([]byte, error)
- func (p *Problem) UnmarshalJSON(data []byte) error
- func (p *Problem) WithDetail(v string) *Problem
- func (p *Problem) WithExtension(key string, val any) *Problem
- func (p *Problem) WithInstance(v string) *Problem
- func (p *Problem) WithStatus(v int) *Problem
- func (p *Problem) WithTitle(v string) *Problem
- func (p *Problem) WithType(v string) *Problem
- func (p *Problem) WithoutExtension(key string) *Problem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Problem ¶
type Problem struct {
Status int `json:"status,omitempty"`
Instance string `json:"instance,omitempty"`
Detail string `json:"detail,omitempty"`
Title string `json:"title,omitempty"`
Type string `json:"type,omitempty"`
Extensions map[string]any `json:"-"`
}
Problem is a struct that represents a problem instance as defined in RFC-9457 (https://tools.ietf.org/html/rfc9457). All fields are optional.
func (*Problem) JSON ¶
func (p *Problem) JSON(w http.ResponseWriter)
JSON writes a JSON response to the client. Handles JSON encoding errors and returns an RFC-9457 compliant JSON error object.
func (Problem) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface to serialize the Problem instance into RFC-9457 JSON format.
func (*Problem) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface to unserialize the JSON string into Problem structure as RFC-9457 implementation. [IMPORTANT]: built-in json.Unmarshaler converts numeric values to float64, so we need to convert status code back to int. The extension values are not converted, but are available.
func (*Problem) WithDetail ¶
WithDetail sets the problem detail.
func (*Problem) WithExtension ¶
WithExtension adds key:value pairs to internal Extensions map. When JSON serialization is performed, these pairs are included in the JSON response as key:value to the final response.
func (*Problem) WithInstance ¶
WithInstance sets the instance URI.
func (*Problem) WithStatus ¶
WithStatus sets the status code.
func (*Problem) WithoutExtension ¶
WithoutExtension removes a key from internal Extensions map. If the key does not exist, it does nothing.