Documentation
¶
Index ¶
- Constants
- func EncodeMap(e *xml.Encoder, ex map[string]interface{}) error
- func NewBadRequest(err error, params ...InvalidParam) func(p *ProblemDetails) Problem
- func NewCodeProblem(code string, typ ...string) func(p *ProblemDetails) Problem
- func RegisterXmlMarshaller(name string, fn XmlMarshaler) error
- func RegisterXmlUnmarshaler(name string, fn XmlUnmarshaler) error
- func WriteJson(ctx context.Context, w http.ResponseWriter, status int, v interface{})
- func WriteXml(ctx context.Context, w http.ResponseWriter, status int, v interface{})
- type Arg
- type BadRequest
- type Builder
- func (b *Builder) BadGateway(format string, args ...interface{}) Problem
- func (b *Builder) BadRequest(format string, args ...interface{}) Problem
- func (b *Builder) Build(status int, format string, args ...interface{}) Problem
- func (b *Builder) Conflict(format string, args ...interface{}) Problem
- func (b *Builder) ExpectationFailed(format string, args ...interface{}) Problem
- func (b *Builder) FailedDependency(format string, args ...interface{}) Problem
- func (b *Builder) Forbidden(format string, args ...interface{}) Problem
- func (b *Builder) GatewayTimeout(format string, args ...interface{}) Problem
- func (b *Builder) Gone(format string, args ...interface{}) Problem
- func (b *Builder) HTTPVersionNotSupported(format string, args ...interface{}) Problem
- func (b *Builder) InsufficientStorage(format string, args ...interface{}) Problem
- func (b *Builder) InternalServerError(format string, args ...interface{}) Problem
- func (b *Builder) LengthRequired(format string, args ...interface{}) Problem
- func (b *Builder) Locked(format string, args ...interface{}) Problem
- func (b *Builder) LoopDetected(format string, args ...interface{}) Problem
- func (b *Builder) MethodNotAllowed(format string, args ...interface{}) Problem
- func (b *Builder) MisdirectedRequest(format string, args ...interface{}) Problem
- func (b *Builder) NetworkAuthenticationRequired(format string, args ...interface{}) Problem
- func (b *Builder) NotAcceptable(format string, args ...interface{}) Problem
- func (b *Builder) NotExtended(format string, args ...interface{}) Problem
- func (b *Builder) NotFound(format string, args ...interface{}) Problem
- func (b *Builder) NotImplemented(format string, args ...interface{}) Problem
- func (b *Builder) PaymentRequired(format string, args ...interface{}) Problem
- func (b *Builder) PreconditionFailed(format string, args ...interface{}) Problem
- func (b *Builder) PreconditionRequired(format string, args ...interface{}) Problem
- func (b *Builder) ProxyAuthRequired(format string, args ...interface{}) Problem
- func (b *Builder) RequestEntityTooLarge(format string, args ...interface{}) Problem
- func (b *Builder) RequestHeaderFieldsTooLarge(format string, args ...interface{}) Problem
- func (b *Builder) RequestTimeout(format string, args ...interface{}) Problem
- func (b *Builder) RequestURITooLong(format string, args ...interface{}) Problem
- func (b *Builder) RequestedRangeNotSatisfiable(format string, args ...interface{}) Problem
- func (b *Builder) ServiceUnavailable(format string, args ...interface{}) Problem
- func (b *Builder) Teapot(format string, args ...interface{}) Problem
- func (b *Builder) TooEarly(format string, args ...interface{}) Problem
- func (b *Builder) TooManyRequests(format string, args ...interface{}) Problem
- func (b *Builder) Type(format string, args ...interface{}) *Builder
- func (b *Builder) Unauthorized(format string, args ...interface{}) Problem
- func (b *Builder) Unavailable(format string, args ...interface{}) Problem
- func (b *Builder) UnavailableForLegalReasons(format string, args ...interface{}) Problem
- func (b *Builder) UnprocessableEntity(format string, args ...interface{}) Problem
- func (b *Builder) UnsupportedMediaType(format string, args ...interface{}) Problem
- func (b *Builder) UpgradeRequired(format string, args ...interface{}) Problem
- func (b *Builder) VariantAlsoNegotiates(format string, args ...interface{}) Problem
- type CodeProblem
- type DefaultProblem
- type Extendable
- type FromError
- type InvalidParam
- type MsgFunc
- type Option
- func Code(code string) Option
- func Detail(detail string) Option
- func Error(err error) Option
- func Extension(key string, value interface{}) Option
- func Instance(instance string) Option
- func InvalidParams(err error, params ...InvalidParam) Option
- func Path(req *http.Request) Option
- func Status(status int) Option
- func Tag(tag string) Option
- func Title(title string) Option
- func Type(format string, args ...interface{}) Option
- func ValidationErrors(err error, verrs ...ValidationError) Option
- type Problem
- func As(err error, status ...int) (Problem, bool)
- func Bind(ctx context.Context, status int, body []byte, f ...func(status int) Problem) (problem Problem, err error)
- func Decode(ctx context.Context, status int, body io.Reader, f ...func(status int) Problem) (problem Problem, err error)
- func DecodeJson(ctx context.Context, status int, body io.Reader, f ...func(status int) Problem) (problem Problem, err error)
- func DecodeXml(ctx context.Context, status int, body io.Reader, f ...func(status int) Problem) (problem Problem, err error)
- func Of(ctx context.Context, path string, err error, args ...Arg) Problem
- func ServerProblemOf(ctx context.Context, path string, err error, f ...MsgFunc) Problem
- func UnmarshalJson(ctx context.Context, status int, body []byte, f ...func(status int) Problem) (problem Problem, err error)
- func UnmarshalXml(ctx context.Context, status int, body []byte, f ...func(status int) Problem) (problem Problem, err error)
- type ProblemDetail
- type ProblemDetails
- func (p *ProblemDetails) Error() string
- func (p *ProblemDetails) Extended() bool
- func (p *ProblemDetails) Extension(key string, value interface{})
- func (p *ProblemDetails) JSON(ctx context.Context, w http.ResponseWriter)
- func (p *ProblemDetails) Map() (map[string]interface{}, bool)
- func (p *ProblemDetails) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (p *ProblemDetails) Message() string
- func (p *ProblemDetails) Problem() Problem
- func (p *ProblemDetails) ProblemStatus() int
- func (p *ProblemDetails) SetCode(code string)
- func (p *ProblemDetails) SetDetail(detail string)
- func (p *ProblemDetails) SetInstance(instance string)
- func (p *ProblemDetails) SetInvalidParams(params []InvalidParam)
- func (p *ProblemDetails) SetParams(url, detail string)
- func (p *ProblemDetails) SetStatus(status int)
- func (p *ProblemDetails) SetTitle(title string)
- func (p *ProblemDetails) SetType(url string)
- func (p *ProblemDetails) SetValidationErrors(ve []ValidationError)
- func (p *ProblemDetails) StatusCode() int
- func (p *ProblemDetails) String() string
- func (p *ProblemDetails) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (p *ProblemDetails) Unwrap() error
- func (p *ProblemDetails) WithMessage(format string, args ...interface{}) Problem
- func (p *ProblemDetails) Wrap() error
- func (p *ProblemDetails) WrapError(err error)
- func (p *ProblemDetails) XML(ctx context.Context, w http.ResponseWriter)
- type ProblemError
- type ProblemExtension
- type ProblemInstance
- type ProblemStatus
- type ProblemTitle
- type ProblemType
- type Renderer
- type ValidationError
- type Wrapper
- type XmlMarshaler
- type XmlUnmarshaler
Constants ¶
const ( Ns9457 = "urn:ietf:rfc:9457" Ns7807 = "urn:ietf:rfc:7807" )
const (
DefaultType = "about:blank"
)
Variables ¶
This section is empty.
Functions ¶
func NewBadRequest ¶
func NewBadRequest(err error, params ...InvalidParam) func(p *ProblemDetails) Problem
NewBadRequest Deprecated: use ValidationErrors instead
func NewCodeProblem ¶
func NewCodeProblem(code string, typ ...string) func(p *ProblemDetails) Problem
NewCodeProblem Deprecated: use Code instead
func RegisterXmlMarshaller ¶
func RegisterXmlMarshaller(name string, fn XmlMarshaler) error
func RegisterXmlUnmarshaler ¶
func RegisterXmlUnmarshaler(name string, fn XmlUnmarshaler) error
Types ¶
type Arg ¶
type Arg func(*option)
func WithFromError ¶
func WithMessage ¶
WithMessage sets a custom message for the Problem.
type BadRequest ¶
type BadRequest interface {
SetValidationErrors(ve []ValidationError)
SetInvalidParams(params []InvalidParam)
}
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) BadGateway ¶
func (*Builder) BadRequest ¶
func (*Builder) ExpectationFailed ¶
func (*Builder) FailedDependency ¶
func (*Builder) GatewayTimeout ¶
func (*Builder) HTTPVersionNotSupported ¶
func (*Builder) InsufficientStorage ¶
func (*Builder) InternalServerError ¶
func (*Builder) LengthRequired ¶
func (*Builder) LoopDetected ¶
func (*Builder) MethodNotAllowed ¶
func (*Builder) MisdirectedRequest ¶
func (*Builder) NetworkAuthenticationRequired ¶
func (*Builder) NotAcceptable ¶
func (*Builder) NotExtended ¶
func (*Builder) NotImplemented ¶
func (*Builder) PaymentRequired ¶
func (*Builder) PreconditionFailed ¶
func (*Builder) PreconditionRequired ¶
func (*Builder) ProxyAuthRequired ¶
func (*Builder) RequestEntityTooLarge ¶
func (*Builder) RequestHeaderFieldsTooLarge ¶
func (*Builder) RequestTimeout ¶
func (*Builder) RequestURITooLong ¶
func (*Builder) RequestedRangeNotSatisfiable ¶
func (*Builder) ServiceUnavailable ¶
func (*Builder) TooManyRequests ¶
func (*Builder) Unauthorized ¶
func (*Builder) Unavailable ¶
Unavailable is an alias for ServiceUnavailable Deprecated: Use ServiceUnavailable instead
func (*Builder) UnavailableForLegalReasons ¶
func (*Builder) UnprocessableEntity ¶
func (*Builder) UnsupportedMediaType ¶
func (*Builder) UpgradeRequired ¶
func (*Builder) VariantAlsoNegotiates ¶
type CodeProblem ¶
type CodeProblem interface {
SetCode(code string)
}
type DefaultProblem ¶
type DefaultProblem = ProblemDetail
DefaultProblem Deprecated: use ProblemDetail instead
type Extendable ¶
type InvalidParam ¶
type InvalidParam struct {
XMLName xml.Name `json:"-" xml:"invalid-param"`
Name string `json:"name" xml:"name"`
Reason string `json:"reason" xml:"reason"`
}
func (InvalidParam) MarshalXML ¶
func (ip InvalidParam) MarshalXML(e *xml.Encoder, start xml.StartElement) error
type Option ¶
func InvalidParams ¶
func InvalidParams(err error, params ...InvalidParam) Option
InvalidParams Create RFC7807-style validation error messages
func ValidationErrors ¶
func ValidationErrors(err error, verrs ...ValidationError) Option
ValidationErrors Create RFC9457-style validation error messages.
type Problem ¶
type Problem interface {
// ProblemStatus returns the status code of the problem.
// Deprecated: Use StatusCode instead.
ProblemStatus() int
// StatusCode returns the status code of the problem.
StatusCode() int
Error() string
Wrap() error
String() string
WithMessage(format string, args ...interface{}) Problem
Message() string
Renderer
}
func Bind ¶
func Bind(ctx context.Context, status int, body []byte, f ...func(status int) Problem) (problem Problem, err error)
Bind is a convenience function to bind the request body to a Problem instance. Deprecated: Use UnmarshalJson instead.
func Decode ¶
func Decode(ctx context.Context, status int, body io.Reader, f ...func(status int) Problem) (problem Problem, err error)
Decode is a convenience function to decode the request body into a Problem instance. Deprecated: Use DecodeJson instead.
func DecodeJson ¶
func DecodeJson(ctx context.Context, status int, body io.Reader, f ...func(status int) Problem) (problem Problem, err error)
DecodeJson is a convenience function to decode the io.Reader into a Problem instance.
func DecodeXml ¶
func DecodeXml(ctx context.Context, status int, body io.Reader, f ...func(status int) Problem) (problem Problem, err error)
DecodeXml is a convenience function to decode the io.Reader into a Problem instance.
func ServerProblemOf ¶
ServerProblemOf 旧バージョン互換用 Deprecated: use Of instead
type ProblemDetail ¶
type ProblemDetail interface {
SetDetail(detail string)
}
type ProblemDetails ¶
type ProblemDetails struct {
XMLName xml.Name `json:"-" xml:"problem"`
Xmlns string `json:"-" xml:"xmlns,attr"`
Type string `json:"type" xml:"type"`
Title string `json:"title" xml:"title,attr,omitempty"`
Status int `json:"status,omitempty" xml:"status,attr,omitempty"`
Detail string `json:"detail,omitempty" xml:"xsd:detail,attr,omitempty"`
Instance string `json:"instance,omitempty" xml:"instance,attr,omitempty"`
Code string `json:"code,omitempty" xml:"code,attr,omitempty"`
InvalidParams []InvalidParam `json:"invalid-params,omitempty" xml:"invalid-params,omitempty"`
Errors []ValidationError `json:"errors,omitempty" xml:"errors,omitempty"`
// contains filtered or unexported fields
}
func NewDetails ¶
func NewDetails(status int) *ProblemDetails
NewDetails creates a new ProblemDetails instance with the given status code.
func (*ProblemDetails) Error ¶
func (p *ProblemDetails) Error() string
Error returns the JSON representation of the ProblemDetails struct.
func (*ProblemDetails) Extended ¶
func (p *ProblemDetails) Extended() bool
Extended checks if the ProblemDetails struct has any extensions.
func (*ProblemDetails) Extension ¶
func (p *ProblemDetails) Extension(key string, value interface{})
func (*ProblemDetails) JSON ¶
func (p *ProblemDetails) JSON(ctx context.Context, w http.ResponseWriter)
JSON marshals the ProblemDetails struct into JSON format.
func (*ProblemDetails) Map ¶
func (p *ProblemDetails) Map() (map[string]interface{}, bool)
Map returns a map representation of the ProblemDetails struct.
func (*ProblemDetails) MarshalXML ¶
func (p *ProblemDetails) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML marshals the ProblemDetails struct into XML format.
func (*ProblemDetails) Message ¶
func (p *ProblemDetails) Message() string
Message returns the detail message of the problem.
func (*ProblemDetails) Problem ¶
func (p *ProblemDetails) Problem() Problem
Problem 旧バージョン互換用 Deprecated: use ProblemDetails instead
func (*ProblemDetails) ProblemStatus ¶
func (p *ProblemDetails) ProblemStatus() int
ProblemStatus returns the status code of the problem. Deprecated: Use StatusCode instead.
func (*ProblemDetails) SetCode ¶
func (p *ProblemDetails) SetCode(code string)
func (*ProblemDetails) SetDetail ¶
func (p *ProblemDetails) SetDetail(detail string)
func (*ProblemDetails) SetInstance ¶
func (p *ProblemDetails) SetInstance(instance string)
func (*ProblemDetails) SetInvalidParams ¶
func (p *ProblemDetails) SetInvalidParams(params []InvalidParam)
func (*ProblemDetails) SetParams ¶
func (p *ProblemDetails) SetParams(url, detail string)
func (*ProblemDetails) SetStatus ¶
func (p *ProblemDetails) SetStatus(status int)
func (*ProblemDetails) SetTitle ¶
func (p *ProblemDetails) SetTitle(title string)
func (*ProblemDetails) SetType ¶
func (p *ProblemDetails) SetType(url string)
func (*ProblemDetails) SetValidationErrors ¶
func (p *ProblemDetails) SetValidationErrors(ve []ValidationError)
func (*ProblemDetails) StatusCode ¶
func (p *ProblemDetails) StatusCode() int
StatusCode returns the status code of the problem.
func (*ProblemDetails) String ¶
func (p *ProblemDetails) String() string
String returns the JSON representation of the ProblemDetails struct.
func (*ProblemDetails) UnmarshalXML ¶
func (p *ProblemDetails) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML unmarshals the XML data into the ProblemDetails struct.
func (*ProblemDetails) Unwrap ¶
func (p *ProblemDetails) Unwrap() error
Unwrap returns the underlying error wrapped by the ProblemDetails struct.
func (*ProblemDetails) WithMessage ¶
func (p *ProblemDetails) WithMessage(format string, args ...interface{}) Problem
WithMessage sets the detail message of the problem.
func (*ProblemDetails) Wrap ¶
func (p *ProblemDetails) Wrap() error
Wrap wraps the ProblemDetails struct with an error.
func (*ProblemDetails) WrapError ¶
func (p *ProblemDetails) WrapError(err error)
func (*ProblemDetails) XML ¶
func (p *ProblemDetails) XML(ctx context.Context, w http.ResponseWriter)
XML marshals the ProblemDetails struct into XML format.
type ProblemError ¶
type ProblemError = ProblemDetails
ProblemError Deprecated: use ProblemDetails instead
type ProblemExtension ¶
type ProblemExtension interface {
Extension(key string, value interface{})
}
type ProblemInstance ¶
type ProblemInstance interface {
SetInstance(instance string)
}
type ProblemStatus ¶
type ProblemStatus interface {
SetStatus(status int)
}
type ProblemTitle ¶
type ProblemTitle interface {
SetTitle(title string)
}
type ProblemType ¶
type ProblemType interface {
SetType(url string)
}
type Renderer ¶
type Renderer interface {
JSON(ctx context.Context, w http.ResponseWriter)
XML(ctx context.Context, w http.ResponseWriter)
}
type ValidationError ¶
type ValidationError struct {
XMLName xml.Name `json:"-" xml:"error"`
Detail string `json:"detail" xml:"detail"`
Pointer string `json:"pointer" xml:"pointer"`
}
func (ValidationError) Error ¶
func (ve ValidationError) Error() string
func (ValidationError) MarshalXML ¶
func (ve ValidationError) MarshalXML(e *xml.Encoder, start xml.StartElement) error
type XmlMarshaler ¶
type XmlMarshaler func(e *xml.Encoder, start xml.StartElement, v interface{}) error
type XmlUnmarshaler ¶
type XmlUnmarshaler func(d *xml.Decoder, start xml.StartElement) (interface{}, error)
func BoolArray ¶
func BoolArray() XmlUnmarshaler
func Float32Array ¶
func Float32Array() XmlUnmarshaler
func Float64Array ¶
func Float64Array() XmlUnmarshaler
func Int8Array ¶
func Int8Array() XmlUnmarshaler
func Int16Array ¶
func Int16Array() XmlUnmarshaler
func Int32Array ¶
func Int32Array() XmlUnmarshaler
func Int64Array ¶
func Int64Array() XmlUnmarshaler
func IntArray ¶
func IntArray() XmlUnmarshaler
func StringArray ¶
func StringArray() XmlUnmarshaler