Documentation
¶
Index ¶
- Constants
- func Code(err error) int
- func Reason(err error) string
- type Catalog
- type Error
- func BadRequest(message Message, opts ...Option) *Error
- func ClientClosed(message Message, opts ...Option) *Error
- func Clone(err *Error) *Error
- func Conflict(message Message, opts ...Option) *Error
- func Forbidden(message Message, opts ...Option) *Error
- func FromError(err error) *Error
- func GatewayTimeout(message Message, opts ...Option) *Error
- func InternalServer(message Message, opts ...Option) *Error
- func New(code int, message Message, opts ...Option) *Error
- func NotFound(message Message, opts ...Option) *Error
- func ServiceUnavailable(message Message, opts ...Option) *Error
- func TooManyRequests(message Message, opts ...Option) *Error
- func Unauthorized(message Message, opts ...Option) *Error
- func Wrap(cause error, code int, message Message, opts ...Option) *Error
- type Handler
- type Message
- type Name
- type Option
- type RenderResult
- type RequestInfo
- type Result
- type TemplateSpec
Constants ¶
View Source
const ( UnknownCode = http.StatusInternalServerError UnknownReason = "UNKNOWN" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Catalog ¶ added in v0.2.0
type Catalog struct {
// contains filtered or unexported fields
}
Catalog 是启动时加载、请求期间只读的多语言文案目录。
func LoadCatalog ¶ added in v0.2.0
LoadCatalog 从 directory 下按 locale 命名的 YAML 文件加载文案。
type Error ¶ added in v0.2.0
type Error struct {
Code int32 `json:"code"`
Reason string `json:"reason"`
Message string `json:"message"`
// contains filtered or unexported fields
}
Error 是统一错误对象。导出字段是唯一允许进入客户端响应的内容。
func BadRequest ¶ added in v0.2.0
func ClientClosed ¶ added in v0.2.0
func GatewayTimeout ¶ added in v0.2.0
func InternalServer ¶ added in v0.2.0
func ServiceUnavailable ¶ added in v0.2.0
func TooManyRequests ¶ added in v0.2.0
func Unauthorized ¶ added in v0.2.0
func (*Error) GRPCStatus ¶ added in v0.2.0
GRPCStatus 返回安全的 gRPC status,仅编码公开字段。
type Handler ¶ added in v0.2.0
type Handler struct {
// contains filtered or unexported fields
}
Handler 集中文案渲染、客户端投影和内部诊断日志。
func NewHandler ¶ added in v0.2.0
func NewHandler(catalog *Catalog, logger modularlog.Logger) (*Handler, error)
type Message ¶ added in v0.2.0
type Message struct {
// contains filtered or unexported fields
}
Message 是与具体语言无关的文案定义。With 返回副本,可安全复用全局定义。
func Define ¶ added in v0.2.0
func Define(reason string, spec TemplateSpec) Message
Define 创建可被生成器静态发现的错误文案定义。 非法 reason 或零值模板属于编程错误,会立即 panic。
type Option ¶ added in v0.2.0
type Option func(*Error)
Option 为错误附加仅供诊断使用的信息。
func WithFields ¶ added in v0.2.0
WithFields 设置一组仅写入日志的上下文字段。
type RenderResult ¶ added in v0.2.0
RenderResult 描述本次文案渲染及其回退情况。
type RequestInfo ¶ added in v0.2.0
RequestInfo 是 transport 交给错误处理器的请求关联信息。
type TemplateSpec ¶ added in v0.2.0
type TemplateSpec struct {
// contains filtered or unexported fields
}
TemplateSpec 是由代码默认文案和有序变量槽组成的不可变模板定义。
func Template ¶ added in v0.2.0
func Template(pattern string, names ...Name) TemplateSpec
Template 创建模板定义。仅支持 %v 槽位和 %% 字面量百分号。 非法模板属于编程错误,会立即 panic。
Click to show internal directories.
Click to hide internal directories.