httpclient/define/response.go

61 lines
3.0 KiB
Go
Raw Normal View History

2024-05-31 14:57:25 +08:00
// Package define ...
//
// Description : define ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-05-31 12:34
package define
2024-06-01 18:41:26 +08:00
import (
"github.com/go-resty/resty/v2"
)
2024-05-31 14:57:25 +08:00
// Response 响应的数据结构定义
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:34 2024/5/31
type Response struct {
Header map[string]string `json:"header"` // 响应header
Cookie map[string]string `json:"cookie"` // 响应cookie
2024-06-05 21:54:06 +08:00
Data string `json:"data"` // 响应body
2024-05-31 14:57:25 +08:00
Code string `json:"code"` // 业务状态码
Message string `json:"message"` // 业务状态码描述
2024-06-08 16:02:22 +08:00
Body map[string]any `json:"body"` // 响应数据
2024-06-05 21:54:06 +08:00
ExtendData map[string]string `json:"extend_data"` // 除去 code / message / data 之外的其他数据
2024-05-31 14:57:25 +08:00
HttpCode int `json:"http_code"` // http状态码
HttpCodeStatus string `json:"http_code_status"` // http状态码描述
ResponseDataRule map[string]any `json:"response_data_rule"` // 返回数据的验证规则
Seq int `json:"seq"` // 第几次请求
RequestStartTime int64 `json:"request_start_time"` // 请求开始时间 : ms
2024-06-03 18:42:46 +08:00
RequestFinishTime int64 `json:"request_finish_time"` // 请求完成时间 : ms
2024-05-31 14:57:25 +08:00
UsedTime int64 `json:"used_time"` // 请求耗时 : ms
RestyResponse *resty.Response `json:"-"` // 请求返回
IsSuccess bool `json:"is_success"` // 是否请求成功
2024-06-01 18:41:26 +08:00
RequestCount int `json:"request_count"` // 请求次数
2024-06-05 21:54:06 +08:00
FailInfo *ResponseFailInfo `json:"fail_info"` // 请求失败信息记录
2024-06-03 18:42:46 +08:00
IsCache bool `json:"-"` // 是否命中缓存
CacheKey string `json:"-"` // 缓存key
CacheValue string `json:"-"` // 缓存值
CacheEnable bool `json:"cache_enable"` // 是否允许缓存
CacheError error `json:"-"` // 缓存是否异常
2024-05-31 14:57:25 +08:00
}
2024-06-01 18:41:26 +08:00
2024-06-05 21:54:06 +08:00
// ResponseFailInfo 失败信息
2024-06-01 18:41:26 +08:00
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:48 2024/6/1
2024-06-05 21:54:06 +08:00
type ResponseFailInfo struct {
2024-06-01 18:41:26 +08:00
Type string `json:"type"` // 失败类型
Message string `json:"message"` // 失败信息
}
const (
RequestFailTypeSend = "SEND_REQUEST_FAIL" // 发送请求即失败, 问题出现在客户端
RequestFailTypeClientError = "CLIENT_REQUEST_ERROR" // 请求失败, 原因出在客户端, 对应http code 4xx
RequestFailTypeServerError = "SERVER_DEAL_ERROR" // 服务端处理失败, 对应 http code 5xx
RequestFailTypeBusinessError = "SERVICE_BUSINESS_ERROR" // 返回状态码为200, 但是业务状态码非成功
)