请求配置验证, 默认值初始化 + full_url + method验证
This commit is contained in:
17
define/error.go
Normal file
17
define/error.go
Normal file
@ -0,0 +1,17 @@
|
||||
// Package define ...
|
||||
//
|
||||
// Description : define ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-05-31 16:02
|
||||
package define
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrRequestConfigNil = errors.New("REQUEST_CONFIG_NIL") // 请求配置 nil
|
||||
ErrFullUrlEmpty = errors.New("FULL_URL_EMPTY") // 没传 full_url
|
||||
ErrFullUrlInvalid = errors.New("FULL_URL_Invalid") // 请求 full_url 不是 http 或者 https 开头
|
||||
ErrMethodIsNotSupport = errors.New("METHOD_IS_NOT_SUPPORT") // 请求 method不支持
|
||||
)
|
@ -13,17 +13,20 @@ package define
|
||||
//
|
||||
// Date : 17:10 2024/5/24
|
||||
type Request struct {
|
||||
Body map[string]any `json:"body"` // 请求Body
|
||||
Header map[string]string `json:"header"` // 请求Header
|
||||
Cookie map[string]string `json:"cookie"` // 请求Cookie
|
||||
Query map[string]string `json:"query"` // 请求query
|
||||
FullUrl string `json:"full_url"` // 完整的请求URL
|
||||
ContentType string `json:"content_type"` // 请求类型
|
||||
Method string `json:"method"` // 请求方法
|
||||
DataField string `json:"data_field"` // 数据字段
|
||||
CodeField string `json:"code_field"` // 业务状态码字段
|
||||
MessageField string `json:"message_field"` // code描述字段
|
||||
RetryRule *RequestRetryRule `json:"retry_rule"` // 重试规则
|
||||
Body map[string]any `json:"body"` // 请求Body
|
||||
Header map[string]string `json:"header"` // 请求Header
|
||||
Cookie map[string]string `json:"cookie"` // 请求Cookie
|
||||
Query map[string]string `json:"query"` // 请求query
|
||||
FullUrl string `json:"full_url"` // 完整的请求URL
|
||||
ContentType string `json:"content_type"` // 请求类型
|
||||
Method string `json:"method"` // 请求方法
|
||||
DataField string `json:"data_field"` // 数据字段
|
||||
CodeField string `json:"code_field"` // 业务状态码字段
|
||||
MessageField string `json:"message_field"` // code描述字段
|
||||
SuccessCodeList []string `json:"success_code_list"` // 哪些业务状态码视为成功
|
||||
ConnectTimeout int64 `json:"connect_timeout"` // 连接超时时间: ms
|
||||
ReadTimeout int64 `json:"read_timeout"` // 读取超时时间
|
||||
RetryRule *RequestRetryRule `json:"retry_rule"` // 重试规则
|
||||
}
|
||||
|
||||
// RequestRetryRule 重试规则
|
||||
@ -37,3 +40,15 @@ type RequestRetryRule struct {
|
||||
RetryHttpCodeList []int64 `json:"retry_http_code_list"` // 哪些http状态码需要重试
|
||||
RetryBusinessCodeList []string `json:"retry_business_code_list"` // 哪些业务状态码需要重试
|
||||
}
|
||||
|
||||
const (
|
||||
DefaultConnectTimeout = 1000 // 默认连接超时时间
|
||||
DefaultReadTimeout = 1000 // 默认连接读取时间
|
||||
DefaultCodeField = "code" // 默认业务状态码字段
|
||||
DefaultMessageField = "message" // 默认状态码描述字段
|
||||
DefaultDataField = "data" // 默认数据字段
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultSuccessCodeList = []string{"0"} // 默认成功业务状态码
|
||||
)
|
||||
|
Reference in New Issue
Block a user