-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.go
46 lines (38 loc) · 908 Bytes
/
new.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package httpclient
import (
"net/http"
"sync"
)
var (
newOnce sync.Once
newClient *http.Client
)
var (
selfServerName string // 本身服务名称
isDisableCircuitBreaker bool // 子服务熔断开启 默认开启 ,true 关闭
timeOutCfg = map[string]float64{}
childServer = map[string]*Server{}
)
func GetSelfServiceName() string {
return selfServerName
}
func New(name string) *Client {
// transport TODO
newOnce.Do(func() {
newClient = &http.Client{
Transport: http.DefaultTransport,
}
})
cfg, ok := childServer[name]
if !ok {
panic("http_server <" + name + "> service cfg not found! ")
}
timeOutCfg[name] = cfg.Timeout
return &Client{
client: newClient,
host: cfg.Url,
name: name,
discoveryServiceName: cfg.DiscoveryServiceName,
discoveryTag: cfg.DiscoveryTag,
}
}