feat(osi): 打通 Go 侧真实请求验收(T-005)

This commit is contained in:
ila
2026-07-06 23:03:14 +08:00
parent 2a77a4dbc1
commit def95efb1c
12 changed files with 411 additions and 54 deletions
+32 -1
View File
@@ -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)
}
}