package config import ( "github.com/spf13/viper" "github.com/tal-tech/go-zero/core/logx" ) type HostConfig struct { Address string `json:"address"` Port int `json:"port"` } type ApplicationConfig struct { Name string `json:"name"` Rpc HostConfig `json:"rpc"` } type Prometheus struct { HostConfig } type ZipkinConfig struct { HostConfig ZipkinURL string `json:"url"` } type ConsulConfig struct { HostConfig ServiceId string `json:"service_id"` } type RedisConfig struct { HostConfig Pass string `json:"pass"` DB int `json:"db"` PoolSize int `json:"pool_size"` } var ( Cfg *viper.Viper ) func LoadConfig(path string) (config *viper.Viper) { config = viper.New() config.SetConfigFile(path) // 读取配置 if err := config.ReadInConfig(); err != nil { logx.Error(err) } logx.Infof("config %#v", config.Get("http")) return }