feat(osi): 打通 Go 侧真实请求验收(T-005)
This commit is contained in:
+32
-1
@@ -1,6 +1,10 @@
|
||||
package config
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
OSI OSIConfig `mapstructure:"osi"`
|
||||
@@ -38,6 +42,7 @@ type RedisConfig struct {
|
||||
func Load(path string) (Config, error) {
|
||||
v := viper.New()
|
||||
setDefaults(v)
|
||||
bindEnv(v)
|
||||
|
||||
if path != "" {
|
||||
v.SetConfigFile(path)
|
||||
@@ -66,3 +71,29 @@ func setDefaults(v *viper.Viper) {
|
||||
v.SetDefault("circuit_fail_threshold", 5)
|
||||
v.SetDefault("circuit_sleep_sec", 60)
|
||||
}
|
||||
func bindEnv(v *viper.Viper) {
|
||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
v.AutomaticEnv()
|
||||
for _, key := range []string{
|
||||
"osi.base_url",
|
||||
"osi.org_code",
|
||||
"osi.user_name",
|
||||
"osi.ask",
|
||||
"osi.device_sn",
|
||||
"osi.operate_user",
|
||||
"osi.timeout_sec",
|
||||
"osi.socks5_proxy",
|
||||
"phis.base_url",
|
||||
"phis.token",
|
||||
"phis.region_code",
|
||||
"phis.poll_interval_sec",
|
||||
"redis.addr",
|
||||
"redis.db",
|
||||
"report_log_file_dir",
|
||||
"retry_max",
|
||||
"circuit_fail_threshold",
|
||||
"circuit_sleep_sec",
|
||||
} {
|
||||
_ = v.BindEnv(key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user