mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-18 06:03:42 +08:00
🐛 fix: config file loading error
This commit is contained in:
@@ -20,9 +20,9 @@ func InitConf() {
|
||||
common.SysLog("running in debug mode")
|
||||
}
|
||||
|
||||
common.IsMasterNode = viper.GetString("NODE_TYPE") != "slave"
|
||||
common.RequestInterval = time.Duration(viper.GetInt("POLLING_INTERVAL")) * time.Second
|
||||
common.SessionSecret = common.GetOrDefault("SESSION_SECRET", common.SessionSecret)
|
||||
common.IsMasterNode = viper.GetString("node_type") != "slave"
|
||||
common.RequestInterval = time.Duration(viper.GetInt("polling_interval")) * time.Second
|
||||
common.SessionSecret = common.GetOrDefault("session_secret", common.SessionSecret)
|
||||
}
|
||||
|
||||
func setConfigFile() {
|
||||
|
||||
@@ -13,13 +13,13 @@ var RedisEnabled = false
|
||||
|
||||
// InitRedisClient This function is called after init()
|
||||
func InitRedisClient() (err error) {
|
||||
redisConn := viper.GetString("REDIS_CONN_STRING")
|
||||
redisConn := viper.GetString("redis_conn_string")
|
||||
|
||||
if redisConn == "" {
|
||||
SysLog("REDIS_CONN_STRING not set, Redis is not enabled")
|
||||
return nil
|
||||
}
|
||||
if viper.GetInt("SYNC_FREQUENCY") == 0 {
|
||||
if viper.GetInt("sync_frequency") == 0 {
|
||||
SysLog("SYNC_FREQUENCY not set, Redis is disabled")
|
||||
return nil
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func InitRedisClient() (err error) {
|
||||
}
|
||||
|
||||
func ParseRedisOption() *redis.Options {
|
||||
opt, err := redis.ParseURL(viper.GetString("REDIS_CONN_STRING"))
|
||||
opt, err := redis.ParseURL(viper.GetString("redis_conn_string"))
|
||||
if err != nil {
|
||||
FatalLog("failed to parse Redis connection string: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func InitHttpClient() {
|
||||
Transport: trans,
|
||||
}
|
||||
|
||||
relayTimeout := common.GetOrDefault("RELAY_TIMEOUT", 600)
|
||||
relayTimeout := common.GetOrDefault("connect_timeout", 600)
|
||||
if relayTimeout != 0 {
|
||||
HTTPClient.Timeout = time.Duration(relayTimeout) * time.Second
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
func GetWSClient(proxyAddr string) *websocket.Dialer {
|
||||
dialer := &websocket.Dialer{
|
||||
HandshakeTimeout: time.Duration(common.GetOrDefault("CONNECT_TIMEOUT", 5)) * time.Second,
|
||||
HandshakeTimeout: time.Duration(common.GetOrDefault("connect_timeout", 5)) * time.Second,
|
||||
}
|
||||
|
||||
if proxyAddr != "" {
|
||||
|
||||
@@ -53,14 +53,3 @@ func TestImgurUpload(t *testing.T) {
|
||||
fmt.Println(err)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
// func TestSMMSUploadError(t *testing.T) {
|
||||
// InitConfig()
|
||||
// access_token := viper.GetString("notify.dingtalk.token")
|
||||
// secret := "test"
|
||||
// dingTalk := channel.NewDingTalk(access_token, secret)
|
||||
|
||||
// err := dingTalk.Send(context.Background(), "Test Title", "*Test Message*")
|
||||
// fmt.Println(err)
|
||||
// assert.Error(t, err)
|
||||
// }
|
||||
|
||||
@@ -28,7 +28,7 @@ func InitTelegramBot() {
|
||||
return
|
||||
}
|
||||
|
||||
botKey := viper.GetString("TG_BOT_API_KEY")
|
||||
botKey := viper.GetString("tg.bot_api_key")
|
||||
if botKey == "" {
|
||||
common.SysLog("Telegram bot is not enabled")
|
||||
return
|
||||
@@ -48,7 +48,7 @@ func InitTelegramBot() {
|
||||
}
|
||||
|
||||
func StartTelegramBot() {
|
||||
botWebhook := viper.GetString("TG_WEBHOOK_SECRET")
|
||||
botWebhook := viper.GetString("tg.webhook_secret")
|
||||
if botWebhook != "" {
|
||||
if common.ServerAddress == "" {
|
||||
common.SysLog("Telegram bot is not enabled: Server address is not set")
|
||||
@@ -57,7 +57,7 @@ func StartTelegramBot() {
|
||||
}
|
||||
TGWebHookSecret = botWebhook
|
||||
serverAddress := strings.TrimSuffix(common.ServerAddress, "/")
|
||||
urlPath := fmt.Sprintf("/api/telegram/%s", viper.GetString("TG_BOT_API_KEY"))
|
||||
urlPath := fmt.Sprintf("/api/telegram/%s", viper.GetString("tg.bot_api_key"))
|
||||
|
||||
webHookOpts := &ext.AddWebhookOpts{
|
||||
SecretToken: TGWebHookSecret,
|
||||
|
||||
Reference in New Issue
Block a user