package config import ( "github.com/spf13/viper" ) type Config struct { Server ServerConfig `mapstructure:"server"` Database DatabaseConfig `mapstructure:"db"` GLM GLMConfig `mapstructure:"glm"` } type ServerConfig struct { Port int `mapstructure:"port"` } type DatabaseConfig struct { Host string `mapstructure:"host"` Port int `mapstructure:"port"` User string `mapstructure:"user"` Password string `mapstructure:"password"` DBName string `mapstructure:"dbname"` } type GLMConfig struct { APIKey string `mapstructure:"api_key"` BaseURL string `mapstructure:"base_url"` Model string `mapstructure:"model"` } func Load(path string) (*Config, error) { v := viper.New() v.SetConfigFile(path) v.SetConfigType("yaml") if err := v.ReadInConfig(); err != nil { return nil, err } var cfg Config if err := v.Unmarshal(&cfg); err != nil { return nil, err } return &cfg, nil }