Documentation ¶
Overview ¶
Package web 通用的 web 开发框架
Index ¶
- Constants
- func NewLocaleError(format string, v ...any) error
- func NewStackError(err error) error
- type CTXFilter
- type Cache
- type Context
- type FieldError
- type FilterProblem
- type HandlerFunc
- type LocaleStringer
- type Logger
- type Logs
- type Middleware
- type MiddlewareFunc
- type Options
- type QueryUnmarshaler
- type Responser
- func Created(v any, location string) Responser
- func NoContent() Responser
- func NotModified(etag func() (string, bool), body func() (any, error)) Responser
- func OK(v any) Responser
- func Redirect(status int, url string) Responser
- func Response(status int, body any, kv ...string) Responser
- func Status(code int, kv ...string) Responser
- type ResponserFunc
- type Router
- type Server
- type StringPhrase
Constants ¶
View Source
const ( // 特殊的值,当不想向用户展示 type 值时,该对象的 type 会被设置为该值。 ProblemAboutBlank = problems.ProblemAboutBlank // 400 ProblemBadRequest = problems.ProblemBadRequest ProblemPaymentRequired = problems.ProblemPaymentRequired ProblemForbidden = problems.ProblemForbidden ProblemNotFound = problems.ProblemNotFound ProblemMethodNotAllowed = problems.ProblemMethodNotAllowed ProblemNotAcceptable = problems.ProblemNotAcceptable ProblemProxyAuthRequired = problems.ProblemProxyAuthRequired ProblemRequestTimeout = problems.ProblemRequestTimeout ProblemConflict = problems.ProblemConflict ProblemGone = problems.ProblemGone ProblemLengthRequired = problems.ProblemLengthRequired ProblemPreconditionFailed = problems.ProblemPreconditionFailed ProblemRequestEntityTooLarge = problems.ProblemRequestEntityTooLarge ProblemRequestURITooLong = problems.ProblemRequestURITooLong ProblemUnsupportedMediaType = problems.ProblemUnsupportedMediaType ProblemRequestedRangeNotSatisfiable = problems.ProblemRequestedRangeNotSatisfiable ProblemExpectationFailed = problems.ProblemExpectationFailed ProblemTeapot = problems.ProblemTeapot ProblemMisdirectedRequest = problems.ProblemMisdirectedRequest ProblemUnprocessableEntity = problems.ProblemUnprocessableEntity ProblemLocked = problems.ProblemLocked ProblemFailedDependency = problems.ProblemFailedDependency ProblemTooEarly = problems.ProblemTooEarly ProblemUpgradeRequired = problems.ProblemUpgradeRequired ProblemPreconditionRequired = problems.ProblemPreconditionRequired ProblemTooManyRequests = problems.ProblemTooManyRequests ProblemRequestHeaderFieldsTooLarge = problems.ProblemRequestHeaderFieldsTooLarge // 500 ProblemInternalServerError = problems.ProblemInternalServerError ProblemNotImplemented = problems.ProblemNotImplemented ProblemBadGateway = problems.ProblemBadGateway ProblemGatewayTimeout = problems.ProblemGatewayTimeout ProblemHTTPVersionNotSupported = problems.ProblemHTTPVersionNotSupported ProblemVariantAlsoNegotiates = problems.ProblemVariantAlsoNegotiates ProblemInsufficientStorage = problems.ProblemInsufficientStorage ProblemLoopDetected = problems.ProblemLoopDetected ProblemNotExtended = problems.ProblemNotExtended ProblemNetworkAuthenticationRequired = problems.ProblemNetworkAuthenticationRequired )
预定义的 Problem ID 值
View Source
const Version = "0.79.4"
Version 当前框架的版本
Variables ¶
This section is empty.
Functions ¶
func NewLocaleError ¶ added in v0.62.0
NewLocaleError 本地化的错误信息
func NewStackError ¶ added in v0.61.0
NewStackError 为 err 带上调用信息
位置从调用 NewStackError 开始。如果 err 为 nil,则返回 nil。 多次调用 NewStackError 包装,则返回第一次包装的返回值。
如果需要输出调用堆栈信息,需要指定 %+v 标记。
Types ¶
type FieldError ¶ added in v0.66.1
type FieldError = config.FieldError
FieldError 表示配置文件中的字段错误
func NewFieldError ¶ added in v0.66.1
func NewFieldError(field string, msg any) *FieldError
NewFieldError 返回表示配置文件错误的对象
field 表示错误的字段名; msg 表示错误信息,可以是任意类型,如果 msg 是 FieldError 类型, 那么此操作相当于调用了 [FieldError.AddFieldParent];
type FilterProblem ¶ added in v0.74.0
type FilterProblem = server.FilterProblem
type HandlerFunc ¶ added in v0.33.0
type HandlerFunc = server.HandlerFunc
type LocaleStringer ¶ added in v0.43.0
type LocaleStringer = localeutil.LocaleStringer
LocaleStringer 本地化字符串需要实在的接口
type Middleware ¶ added in v0.33.0
type Middleware = server.Middleware
type MiddlewareFunc ¶ added in v0.46.0
type MiddlewareFunc = server.MiddlewareFunc
type QueryUnmarshaler ¶ added in v0.58.0
type QueryUnmarshaler = query.Unmarshaler
QueryUnmarshaler 对查询参数的解析接口
type Responser ¶ added in v0.40.0
func NotModified ¶ added in v0.71.0
NotModified 决定何时可返回 304 状态码
etag 返回当前内容关联的 ETag 报头内容,其原型为:
func()(etag string, weak bool)
etag 表示对应的 etag 报头,需要包含双绰号,但是不需要 W/ 前缀,weak 是否为弱验证。
body 获取返回给客户端的报文主体对象, 如果返回的是 []byte 类型,会原样输出, 其它类型则按照 [Context.Marshal] 进行转换成 []byte 之后输出。
type ResponserFunc ¶ added in v0.56.0
type ResponserFunc = server.ResponserFunc
type StringPhrase ¶ added in v0.78.0
type StringPhrase = localeutil.StringPhrase
Directories ¶
Path | Synopsis |
---|---|
Package app 提供了简便的方式初始化 [server.Server]
|
Package app 提供了简便的方式初始化 [server.Server] |
Package cache 统一的缓存系统接口
|
Package cache 统一的缓存系统接口 |
caches
Package caches 内置的缓存接口实现
|
Package caches 内置的缓存接口实现 |
cachetest
Package cachetest 缓存的测试用例
|
Package cachetest 缓存的测试用例 |
cmd
|
|
web
Module
|
|
Package filter 过滤器
|
Package filter 过滤器 |
internal
|
|
encoding
Package encoding 处理 Accept-encoding 报头内容
|
Package encoding 处理 Accept-encoding 报头内容 |
errs
Package errs 与错误相关的定义
|
Package errs 与错误相关的定义 |
header
Package header 与报头相关的处理方法
|
Package header 与报头相关的处理方法 |
locale
Package locale 用于处理本地化文件的加载
|
Package locale 用于处理本地化文件的加载 |
mimetypes
Package mimetypes 管理与 Mimetype 相关的数据
|
Package mimetypes 管理与 Mimetype 相关的数据 |
problems
Package problems 提供对 Problem 相关内容的管理
|
Package problems 提供对 Problem 相关内容的管理 |
Package locales 为 web 包提供了本地化的内容
|
Package locales 为 web 包提供了本地化的内容 |
Package logs 日志操作
|
Package logs 日志操作 |
Package serializer 序列化的相关操作
|
Package serializer 序列化的相关操作 |
form
Package form 用于处理 www-form-urlencoded 编码
|
Package form 用于处理 www-form-urlencoded 编码 |
html
Package html 提供输出 HTML 内容的解码函数
|
Package html 提供输出 HTML 内容的解码函数 |
json
Package json JSON 格式的序列化方法
|
Package json JSON 格式的序列化方法 |
jsonp
Package jsonp JSONP 序列化操作
|
Package jsonp JSONP 序列化操作 |
xml
Package xml XML 编码的序列化操作
|
Package xml XML 编码的序列化操作 |
Package server 服务管理
|
Package server 服务管理 |
servertest
Package servertest 为 server 提供一些简便的测试方
|
Package servertest 为 server 提供一些简便的测试方 |
Click to show internal directories.
Click to hide internal directories.