You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
883B

  1. package config
  2. import (
  3. "github.com/spf13/viper"
  4. "github.com/tal-tech/go-zero/core/logx"
  5. )
  6. type HostConfig struct {
  7. Address string `json:"address"`
  8. Port int `json:"port"`
  9. }
  10. type ApplicationConfig struct {
  11. Name string `json:"name"`
  12. Rpc HostConfig `json:"rpc"`
  13. }
  14. type Prometheus struct {
  15. HostConfig
  16. }
  17. type ZipkinConfig struct {
  18. HostConfig
  19. ZipkinURL string `json:"url"`
  20. }
  21. type ConsulConfig struct {
  22. HostConfig
  23. ServiceId string `json:"service_id"`
  24. }
  25. type RedisConfig struct {
  26. HostConfig
  27. Pass string `json:"pass"`
  28. DB int `json:"db"`
  29. PoolSize int `json:"pool_size"`
  30. }
  31. var (
  32. Cfg *viper.Viper
  33. )
  34. func LoadConfig(path string) (config *viper.Viper) {
  35. config = viper.New()
  36. config.SetConfigFile(path)
  37. // 读取配置
  38. if err := config.ReadInConfig(); err != nil {
  39. logx.Error(err)
  40. }
  41. logx.Infof("config %#v", config.Get("http"))
  42. return
  43. }