Skip to content

Commit cf519fe

Browse files
committed
add missing lock duration config_file loading
1 parent f824d4a commit cf519fe

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

internal/configfile/config_file.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"path/filepath"
66
"strings"
7+
"sync"
78

89
"github.com/BurntSushi/toml"
910
"github.com/qiniu/go-sdk/v7/internal/env"
@@ -18,6 +19,8 @@ type profileConfig struct {
1819

1920
var (
2021
profileConfigs map[string]*profileConfig
22+
profileConfigsError error
23+
profileConfigsOnce sync.Once
2124
ErrInvalidBucketUrl = errors.New("invalid bucket url")
2225
)
2326

@@ -79,9 +82,13 @@ func getProfile() (*profileConfig, error) {
7982
}
8083

8184
func load() error {
82-
if profileConfigs != nil {
83-
return nil
84-
}
85+
profileConfigsOnce.Do(func() {
86+
profileConfigsError = _load()
87+
})
88+
return profileConfigsError
89+
}
90+
91+
func _load() error {
8592
configFilePath := env.ConfigFileFromEnvironment()
8693
if configFilePath == "" {
8794
configFilePath = getDefaultConfigFilePath()

0 commit comments

Comments
 (0)