mirror of
https://git.oceanpay.cc/danial/kami_scripts.git
synced 2025-12-18 21:12:33 +00:00
- 新增配置项 QueryURL,支持自定义查询地址 - 修改QueryCardInput结构体,调整字段名更准确 - 使用resty替代beego httplib,提升请求稳定性和重试能力 - 调整请求URL为kami-spider-monorepo服务地址 - 优化错误重试逻辑,针对验证码识别失败进行重试 - 调整响应解析和错误处理逻辑 - 更新order_service调用,传递新配置和请求参数 - 升级多个依赖包版本,提升模块稳定性和安全性 - 修正配置文件config.yaml中字段及格式,使配置更合理
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package config
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// Config 应用配置结构
|
|
type Config struct {
|
|
QueryURL string `mapstructure:"query_url"`
|
|
Database struct {
|
|
Host string `mapstructure:"host"`
|
|
Port int `mapstructure:"port"`
|
|
Username string `mapstructure:"username"`
|
|
Password string `mapstructure:"password"`
|
|
DBName string `mapstructure:"dbname"`
|
|
} `mapstructure:"database"`
|
|
Merchants []*struct {
|
|
Name string `mapstructure:"name"`
|
|
SubmitURL string `mapstructure:"submit_url"`
|
|
ProductCode string `mapstructure:"product_code"`
|
|
PayKey string `mapstructure:"pay_key"`
|
|
PaySecret string `mapstructure:"pay_secret"`
|
|
CardType string `mapstructure:"card_type"`
|
|
} `mapstructure:"merchants"`
|
|
Logging struct {
|
|
Level string `mapstructure:"level"`
|
|
Filename string `mapstructure:"filename"`
|
|
MaxSize int `mapstructure:"max_size"`
|
|
MaxBackups int `mapstructure:"max_backups"`
|
|
MaxAge int `mapstructure:"max_age"`
|
|
Compress bool `mapstructure:"compress"`
|
|
} `mapstructure:"logging"`
|
|
}
|
|
|
|
var (
|
|
config *Config
|
|
once sync.Once
|
|
)
|
|
|
|
// GetConfig 获取配置单例
|
|
func GetConfig() *Config {
|
|
once.Do(func() {
|
|
config = &Config{}
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("yaml")
|
|
viper.AddConfigPath(".")
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
panic("Error reading config file: " + err.Error())
|
|
}
|
|
|
|
if err := viper.Unmarshal(config); err != nil {
|
|
panic("Error unmarshaling config: " + err.Error())
|
|
}
|
|
})
|
|
return config
|
|
}
|