problems

package
v0.79.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package problems 提供对 Problem 相关内容的管理

Index

Constants

View Source
const (
	// 特殊值,当不希望显示 type 值时,将 type 赋予此值,不应该出现相应的状态码。
	ProblemAboutBlank = "about:blank"

	// 400
	ProblemBadRequest                   = "400"
	ProblemUnauthorized                 = "401"
	ProblemPaymentRequired              = "402"
	ProblemForbidden                    = "403"
	ProblemNotFound                     = "404"
	ProblemMethodNotAllowed             = "405"
	ProblemNotAcceptable                = "406"
	ProblemProxyAuthRequired            = "407"
	ProblemRequestTimeout               = "408"
	ProblemConflict                     = "409"
	ProblemGone                         = "410"
	ProblemLengthRequired               = "411"
	ProblemPreconditionFailed           = "412"
	ProblemRequestEntityTooLarge        = "413"
	ProblemRequestURITooLong            = "414"
	ProblemUnsupportedMediaType         = "415"
	ProblemRequestedRangeNotSatisfiable = "416"
	ProblemExpectationFailed            = "417"
	ProblemTeapot                       = "418"
	ProblemMisdirectedRequest           = "421"
	ProblemUnprocessableEntity          = "422"
	ProblemLocked                       = "423"
	ProblemFailedDependency             = "424"
	ProblemTooEarly                     = "425"
	ProblemUpgradeRequired              = "426"
	ProblemPreconditionRequired         = "428"
	ProblemTooManyRequests              = "429"
	ProblemRequestHeaderFieldsTooLarge  = "431"
	ProblemUnavailableForLegalReasons   = "451"

	// 500
	ProblemInternalServerError           = "500"
	ProblemNotImplemented                = "501"
	ProblemBadGateway                    = "502"
	ProblemServiceUnavailable            = "503"
	ProblemGatewayTimeout                = "504"
	ProblemHTTPVersionNotSupported       = "505"
	ProblemVariantAlsoNegotiates         = "506"
	ProblemInsufficientStorage           = "507"
	ProblemLoopDetected                  = "508"
	ProblemNotExtended                   = "510"
	ProblemNetworkAuthenticationRequired = "511"
)

预定义的 Problem id 值

Variables

This section is empty.

Functions

func IsValidStatus added in v0.70.0

func IsValidStatus(status int) bool

func Status

func Status(id string) int

Types

type Problems

type Problems[P any] struct {
	// contains filtered or unexported fields
}

Problems 管理 Problem

P 表示 Problem 接口类型

func New

func New[P any](prefix string, builder func(id string, status int, title, detail string) P) *Problems[P]

func (*Problems[P]) Add

func (p *Problems[P]) Add(id string, status int, title, detail localeutil.LocaleStringer)

func (*Problems[P]) Problem

func (p *Problems[P]) Problem(printer *localeutil.Printer, id string) P

func (*Problems[P]) Visit added in v0.70.0

func (p *Problems[P]) Visit(visit func(prefix, id string, status int, title, detail localeutil.LocaleStringer))

type RFC7807

type RFC7807[C ctx] struct {
	// contains filtered or unexported fields
}

RFC7807 server.Problem 接口的 rfc7807 实现

C 表示实现的 server.Context 类型, 因为此类型最终会被 server 包引用,为了拆分代码,用泛型代替。

func (*RFC7807[C]) AddParam

func (p *RFC7807[C]) AddParam(name string, reason string)

func (*RFC7807[C]) Apply

func (p *RFC7807[C]) Apply(ctx C)

func (*RFC7807[C]) MarshalForm

func (p *RFC7807[C]) MarshalForm() ([]byte, error)

func (*RFC7807[C]) MarshalHTML

func (p *RFC7807[C]) MarshalHTML() (string, any)

func (*RFC7807[C]) MarshalJSON

func (p *RFC7807[C]) MarshalJSON() ([]byte, error)

func (*RFC7807[C]) MarshalXML

func (p *RFC7807[C]) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*RFC7807[C]) With

func (p *RFC7807[C]) With(key string, val any)

type RFC7807Pool

type RFC7807Pool[C ctx] struct {
	// contains filtered or unexported fields
}

func NewRFC7807Pool

func NewRFC7807Pool[C ctx]() *RFC7807Pool[C]

func (*RFC7807Pool[C]) New

func (pool *RFC7807Pool[C]) New(id string, status int, title, detail string) *RFC7807[C]

New 获取 RFC7807 对象

Jump to

Keyboard shortcuts

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