httpclient/client.go

94 lines
2.2 KiB
Go
Raw Normal View History

// Package httpclient ...
//
// Description : httpclient ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-05-31 15:22
package httpclient
import (
"git.zhangdeman.cn/gateway/httpclient/define"
"git.zhangdeman.cn/gateway/httpclient/validate"
"github.com/go-resty/resty/v2"
)
// NewHttpClient 获取http client
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:27 2024/5/31
func NewHttpClient(reqConfig *define.Request) (*HttpClient, error) {
// 验证配置正确性以及初始化默认值
if err := validate.RequestConfig(reqConfig); nil != err {
return nil, err
}
2024-05-31 18:00:24 +08:00
restyClient, restyRequest := NewRestyClient(reqConfig)
hc := &HttpClient{
Client: restyClient,
request: restyRequest,
reqConfig: reqConfig,
}
return hc, nil
}
// HttpClient 请求客户端
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:27 2024/5/31
type HttpClient struct {
*resty.Client
2024-05-31 18:00:24 +08:00
request *resty.Request
reqConfig *define.Request
}
// getRequestValidateMiddleware 请求验证的Middleware
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:40 2024/5/31
func (hc *HttpClient) getRequestValidateMiddleware() resty.RequestMiddleware {
return func(client *resty.Client, request *resty.Request) error {
return nil
}
}
// getResponseValidateMiddleware 获取相应数据验证的middleware
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:42 2024/5/31
func (hc *HttpClient) getResponseValidateMiddleware() resty.ResponseMiddleware {
return func(client *resty.Client, response *resty.Response) error {
return nil
}
}
// SetRestyClient 设置client
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:54 2024/5/31
func (hc *HttpClient) SetRestyClient(restyClient *resty.Client) {
hc.Client = restyClient
}
// GetRestyClient 获取 resty client
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:57 2024/5/31
func (hc *HttpClient) GetRestyClient() *resty.Client {
return hc.Client
}
// Request 发送请求
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:52 2024/5/31
func (hc *HttpClient) Request(reqConfig *define.Request) *define.Response {
return nil
}