增加获取http client方法
This commit is contained in:
22
rpc.go
22
rpc.go
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user