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) }