add lock for httpclient
This commit is contained in:
parent
209ef78919
commit
e26621a43c
20
api.go
20
api.go
@ -109,11 +109,25 @@ func init() {
|
|||||||
gojsObj := gojs.Map{}
|
gojsObj := gojs.Map{}
|
||||||
|
|
||||||
for cloudName, actions := range fixedCloudConfigs {
|
for cloudName, actions := range fixedCloudConfigs {
|
||||||
httpClients[cloudName] = map[int]*httpclient.ClientPool{}
|
httpClientsLock.RLock()
|
||||||
|
hcSet := httpClients[cloudName]
|
||||||
|
httpClientsLock.RUnlock()
|
||||||
|
if hcSet == nil {
|
||||||
|
hcSet = map[int]*httpclient.ClientPool{}
|
||||||
|
httpClientsLock.Lock()
|
||||||
|
httpClients[cloudName] = hcSet
|
||||||
|
httpClientsLock.Unlock()
|
||||||
|
}
|
||||||
cloudObj := map[string]any{}
|
cloudObj := map[string]any{}
|
||||||
for actionName, action := range actions {
|
for actionName, action := range actions {
|
||||||
if _, ok := httpClients[cloudName][action.Timeout]; !ok {
|
httpClientsLock.RLock()
|
||||||
httpClients[cloudName][action.Timeout] = httpclient.GetClient(time.Duration(action.Timeout) * time.Millisecond)
|
_, hcOK := hcSet[action.Timeout]
|
||||||
|
httpClientsLock.RUnlock()
|
||||||
|
if !hcOK {
|
||||||
|
hc := httpclient.GetClient(time.Duration(action.Timeout) * time.Millisecond)
|
||||||
|
httpClientsLock.Lock()
|
||||||
|
hcSet[action.Timeout] = hc
|
||||||
|
httpClientsLock.Unlock()
|
||||||
}
|
}
|
||||||
cloudObj[actionName] = makeAction(cloudName, action)
|
cloudObj[actionName] = makeAction(cloudName, action)
|
||||||
}
|
}
|
||||||
|
12
go.mod
12
go.mod
@ -3,12 +3,12 @@ module apigo.cc/cloud
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
apigo.cc/gojs v0.0.4
|
apigo.cc/gojs v0.0.12
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/ssgo/config v1.7.9
|
github.com/ssgo/config v1.7.9
|
||||||
github.com/ssgo/httpclient v1.7.8
|
github.com/ssgo/httpclient v1.7.8
|
||||||
github.com/ssgo/log v1.7.7
|
github.com/ssgo/log v1.7.7
|
||||||
github.com/ssgo/u v1.7.11
|
github.com/ssgo/u v1.7.13
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -17,9 +17,9 @@ require (
|
|||||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
||||||
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
|
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
|
||||||
github.com/ssgo/standard v1.7.7 // indirect
|
github.com/ssgo/standard v1.7.7 // indirect
|
||||||
github.com/ssgo/tool v0.4.27 // indirect
|
github.com/ssgo/tool v0.4.28 // indirect
|
||||||
golang.org/x/net v0.31.0 // indirect
|
golang.org/x/net v0.32.0 // indirect
|
||||||
golang.org/x/sys v0.27.0 // indirect
|
golang.org/x/sys v0.28.0 // indirect
|
||||||
golang.org/x/text v0.20.0 // indirect
|
golang.org/x/text v0.21.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user