Documentation
¶
Overview ¶
Package restyoops: Structured HTTP operation fault classification with retryable semantics Oops! See if restyv2 response is retryable Provides Kind enum, Oops struct, and Detect function to categorize HTTP response outcomes
restyoops: 结构化 HTTP 操作故障分类,带有可重试语义 Oops! 检查 restyv2 响应是否可重试 提供 Kind 枚举、Oops 结构体和 Detect 函数来分类 HTTP 响应结果
Index ¶
- type Config
- func (c *Config) WithContentCheck(statusCode int, check ContentCheckFunc) *Config
- func (c *Config) WithDefaultWait(d time.Duration) *Config
- func (c *Config) WithKindRetryable(kind Kind, retryable bool, waitTime time.Duration) *Config
- func (c *Config) WithStatusRetryable(statusCode int, retryable bool, waitTime time.Duration) *Config
- type ContentCheckFunc
- type Detective
- type Kind
- type KindOption
- type Oops
- type OopsIssue
- type StatusOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
StatusOptions map[int]*StatusOption
KindOptions map[Kind]*KindOption
DefaultWait time.Duration // default wait time // 默认等待时间
ContentChecks map[int]ContentCheckFunc // custom content checks // 自定义内容检查
}
Config holds customizable detection settings Config 保存可自定义的检测设置
func NewConfig ¶
func NewConfig() *Config
NewConfig creates a Config with sensible defaults NewConfig 创建带有合理默认值的 Config
func (*Config) WithContentCheck ¶
func (c *Config) WithContentCheck(statusCode int, check ContentCheckFunc) *Config
WithContentCheck adds a custom content check WithContentCheck 添加自定义内容检查
func (*Config) WithDefaultWait ¶
WithDefaultWait sets the default wait time WithDefaultWait 设置默认等待时间
func (*Config) WithKindRetryable ¶
WithKindRetryable sets retryable and wait time based on Kind WithKindRetryable 基于 Kind 设置可重试和等待时间
type ContentCheckFunc ¶
ContentCheckFunc checks content and returns Oops if matched, nil otherwise ContentCheckFunc 检查内容,匹配时返回 Oops,否则返回 nil
type Detective ¶ added in v0.0.1
type Detective struct {
// contains filtered or unexported fields
}
Detective wraps Config and provides a convenient API Detective 封装 Config 并提供便捷的 API
func NewDetective ¶ added in v0.0.1
NewDetective creates a Detective with the specified Config NewDetective 使用指定的 Config 创建 Detective
type Kind ¶
type Kind string
Kind represents the classification of an HTTP operation outcome Used to categorize outcomes into actionable groups
Kind 代表 HTTP 操作结果的分类 用于将结果分类为可操作的组
const ( // KindUnknown indicates unclassified issues // KindUnknown 表示未分类的问题 KindUnknown Kind = "UNKNOWN" // KindNetwork indicates network issues like timeout, DNS, TCP, TLS // Outcomes: connection reset, deadline exceeded, no such host // KindNetwork 表示网络问题,如超时、DNS、TCP、TLS // 结果:连接重置、截止时间超时、无此主机 KindNetwork Kind = "NETWORK" // KindHttp indicates HTTP status code issues (4xx/5xx) // Outcomes: 429 rate limit, 500 issues, 502/503/504 upstream issues // KindHttp 表示 HTTP 状态码问题(4xx/5xx) // 结果:429 限流、500 问题、502/503/504 上游问题 KindHttp Kind = "HTTP" // KindParse indicates response parsing issues // Outcomes: JSON unmarshal failed, unexpected content type // KindParse 表示响应解析问题 // 结果:JSON 反序列化失败、意外的内容类型 KindParse Kind = "PARSE" // KindBlock indicates request was blocked (captcha, WAF, login redirect) // Outcomes: 403 with HTML, 200 with captcha page, redirect to login // KindBlock 表示请求被阻止(验证码、WAF、登录重定向) // 结果:403 带 HTML、200 带验证码页面、重定向到登录 KindBlock Kind = "BLOCK" // KindBusiness indicates business logic issues (HTTP 200 but business code != 0) // Outcomes: rate limited, insufficient balance, invalid params // KindBusiness 表示业务逻辑问题(HTTP 200 但业务码 != 0) // 结果:限流、余额不足、参数无效 KindBusiness Kind = "BUSINESS" )
func (Kind) IsBlock ¶
IsBlock checks if Kind indicates blocked/captcha issues IsBlock 检查 Kind 是否表示被阻止/验证码问题
func (Kind) IsBusiness ¶
IsBusiness checks if Kind indicates business logic issues IsBusiness 检查 Kind 是否表示业务逻辑问题
func (Kind) IsHttp ¶
IsHttp checks if Kind indicates HTTP status issues IsHttp 检查 Kind 是否表示 HTTP 状态问题
func (Kind) IsNetwork ¶
IsNetwork checks if Kind indicates network issues IsNetwork 检查 Kind 是否表示网络问题
type KindOption ¶
KindOption holds retryable and wait time settings KindOption 保存可重试和等待时间设置
type Oops ¶
type Oops struct {
Kind Kind // Classification // 分类
StatusCode int // HTTP status code // HTTP 状态码
ContentType string // Response Content-Type // 响应 Content-Type
Cause error // Wrapped outcome // 被包装的结果
Retryable bool // Can be resolved via retries // 是否可通过重试解决
WaitTime time.Duration // Suggested wait time // 建议等待时间
}
Oops represents a structured HTTP operation outcome Oops 代表结构化的 HTTP 操作结果
func NewUnknown ¶
func NewUnknown() *Oops
NewUnknown creates an Oops indicating unknown issue NewUnknown 创建一个表示未知问题的 Oops
func (*Oops) IsRetryable ¶
IsRetryable checks if retrying is recommended IsRetryable 检查是否建议重试
func (*Oops) WithContentType ¶ added in v0.0.1
WithContentType sets the content type and returns the Oops WithContentType 设置内容类型并返回 Oops
type OopsIssue ¶ added in v0.0.1
type OopsIssue = Oops
OopsIssue is an alias for Oops, for use as return type OopsIssue 是 Oops 的别名,用于作为返回类型
type StatusOption ¶
StatusOption holds retryable and wait time settings StatusOption 保存可重试和等待时间设置
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
utils
Package utils provides utilities supporting the restyoops package Implements generic support functions used across different modules
|
Package utils provides utilities supporting the restyoops package Implements generic support functions used across different modules |