请求配置验证, 默认值初始化 + full_url + method验证
This commit is contained in:
44
resty.go
Normal file
44
resty.go
Normal file
@ -0,0 +1,44 @@
|
||||
// Package httpclient ...
|
||||
//
|
||||
// Description : httpclient ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-05-31 14:59
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/gateway/httpclient/define"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"net/textproto"
|
||||
)
|
||||
|
||||
// NewRestyClient 获取resty client
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:00 2024/5/31
|
||||
func NewRestyClient(requestConfig *define.Request) *resty.Client {
|
||||
formatHeader(requestConfig)
|
||||
client := resty.New()
|
||||
if nil == requestConfig {
|
||||
return client
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
// formatHeader 格式化header
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:18 2024/5/31
|
||||
func formatHeader(requestConfig *define.Request) {
|
||||
if nil == requestConfig {
|
||||
return
|
||||
}
|
||||
formatHeaderData := make(map[string]string)
|
||||
for headerName, headerVal := range requestConfig.Header {
|
||||
formatHeaderData[textproto.CanonicalMIMEHeaderKey(headerName)] = headerVal
|
||||
}
|
||||
requestConfig.Header = formatHeaderData
|
||||
}
|
Reference in New Issue
Block a user