feat: 实现基础的随机转发能力
This commit is contained in:
43
config.go
Normal file
43
config.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type AiTarget struct {
|
||||
TargetURL string `mapstructure:"Target"`
|
||||
OpenAIKey string `mapstructure:"Key"`
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
InKeys []string `mapstructure:"InKeys"`
|
||||
ApiPools map[string][]AiTarget `mapstructure:"ApiPools"`
|
||||
}
|
||||
|
||||
var (
|
||||
config *AppConfig
|
||||
)
|
||||
|
||||
func InitConfig() {
|
||||
v := viper.NewWithOptions(viper.KeyDelimiter("::"))
|
||||
v.SetConfigName("aiproxy")
|
||||
v.SetConfigType("yaml")
|
||||
v.AddConfigPath("/etc/")
|
||||
v.AddConfigPath("$HOME/.config/")
|
||||
v.AddConfigPath(".")
|
||||
|
||||
err := v.ReadInConfig()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("fatal on read config file: %w", err))
|
||||
}
|
||||
err = v.Unmarshal(&config)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("fatal on parse config file: %w", err))
|
||||
}
|
||||
var models []string
|
||||
for k, _ := range config.ApiPools {
|
||||
models = append(models, k)
|
||||
}
|
||||
fmt.Printf("loaded models: %+v", models)
|
||||
}
|
||||
Reference in New Issue
Block a user