增加获取http client方法

This commit is contained in:
2022-06-30 17:15:22 +08:00
parent 0ced660ca2
commit 1326ec76a8
4 changed files with 35 additions and 2 deletions

22
rpc.go
View File

@ -10,7 +10,9 @@ package rpc
import (
"errors"
"sync"
"time"
httpclient "github.com/ddliu/go-httpclient"
"go.uber.org/zap"
)
@ -249,3 +251,23 @@ func (r *request) Connect() error {
func (r *request) Send() error {
return nil
}
// GetHttpClient 获取client实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:00 2022/6/30
func (r *request) GetHttpClient(header map[string]string, timeout ApiTimeout) *httpclient.HttpClient {
client := httpclient.NewHttpClient()
if timeout.Connect <= 0 {
timeout.Connect = DefaultConnectTimeout
}
if timeout.Read <= 0 {
timeout.Read = DefaultReadTimeout
}
client.WithHeaders(header)
client.WithOption(httpclient.OPT_CONNECTTIMEOUT_MS, time.Duration(timeout.Connect)*time.Millisecond)
client.WithOption(httpclient.OPT_TIMEOUT_MS, time.Duration(timeout.Read)*time.Millisecond)
return client
}