请求支持传入动态header

This commit is contained in:
白茶清欢 2022-10-04 00:50:27 +08:00
parent 27e02a3570
commit fb758a6ad4

11
rpc.go
View File

@ -256,7 +256,7 @@ func (r *request) Get() error {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:24 2022/6/30
func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, parameter map[string]interface{}, receiver interface{}) error {
func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, parameter map[string]interface{}, header map[string]string, receiver interface{}) error {
var (
serviceConfig *Service
apiConfig *Api
@ -289,8 +289,15 @@ func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, par
fullURL, body = r.getFullURLAndBody(serviceConfig, apiConfig, parameter)
logDataList = append(logDataList, zap.String("full_utl", fullURL))
fullHeader := make(map[string]string)
for k, v := range apiConfig.Header {
fullHeader[k] = v
}
for k, v := range header {
fullHeader[k] = v
}
// 获取客户端
client = r.GetHttpClient(apiConfig.Header, apiConfig.Timeout)
client = r.GetHttpClient(fullHeader, apiConfig.Timeout)
var bodyReader io.Reader
if nil != body {
logDataList = append(logDataList, zap.String("request_body", string(body)))