httpclient/define/request.go

57 lines
2.5 KiB
Go
Raw Permalink Normal View History

2024-05-24 18:54:23 +08:00
// Package define ...
//
// Description : define ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-05-24 17:09
package define
// Request 请求配置
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:10 2024/5/24
type Request struct {
2024-05-31 18:00:24 +08:00
PathParam map[string]string `json:"path_param"` // 替换url中的占位符
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描述字段
2024-06-05 21:54:06 +08:00
DataReceiver interface{} `json:"-"` // 响应data部分数据解析
SuccessCodeList []string `json:"success_code_list"` // 哪些业务状态码视为成功
ConnectTimeout int64 `json:"connect_timeout"` // 连接超时时间: ms
ReadTimeout int64 `json:"read_timeout"` // 读取超时时间
RetryRule *RequestRetryRule `json:"retry_rule"` // 重试规则
2024-05-31 12:33:36 +08:00
}
// RequestRetryRule 重试规则
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:26 2024/5/31
type RequestRetryRule struct {
RetryCount int `json:"retry_count"` // 重试次数
2024-05-31 12:33:36 +08:00
RetryTimeInterval int64 `json:"retry_time_interval"` // 重试的时间间隔 1 - 10 之间, 单位毫秒
RetryHttpCodeList []int64 `json:"retry_http_code_list"` // 哪些http状态码需要重试
RetryBusinessCodeList []string `json:"retry_business_code_list"` // 哪些业务状态码需要重试
2024-05-24 18:54:23 +08:00
}
const (
DefaultConnectTimeout = 1000 // 默认连接超时时间
DefaultReadTimeout = 1000 // 默认连接读取时间
DefaultCodeField = "code" // 默认业务状态码字段
DefaultMessageField = "message" // 默认状态码描述字段
DefaultDataField = "data" // 默认数据字段
)
var (
DefaultSuccessCodeList = []string{"0"} // 默认成功业务状态码
)