高级排程
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.

68 lines
1.4 KiB

  1. package config
  2. import (
  3. "LAPP_AS/utils"
  4. "fmt"
  5. "github.com/spf13/viper"
  6. )
  7. var AppConfig Config
  8. type Config struct {
  9. *DB `mapstructure:"db"`
  10. *Mongo `mapstructure:"mongo"`
  11. *App `mapstructure:"app"`
  12. *ETCD `mapstructure:"etcd"`
  13. }
  14. type DB struct {
  15. Host string `yaml:"host"`
  16. Port int `yaml:"port"`
  17. User string `yaml:"user"`
  18. Password string `yaml:"password"`
  19. Database string `yaml:"database"`
  20. }
  21. type Mongo struct {
  22. Host string `yaml:"host"`
  23. Port int `yaml:"port"`
  24. DataDB string `yaml:"datadb"`
  25. LogDB string `yaml:"logdb"`
  26. }
  27. type App struct {
  28. Port int `yaml:"port"`
  29. TaskNums int `yaml:"tasknums"`
  30. ErrNums int `yaml:"errnums"`
  31. ShellPath string `yaml:"shellpath"`
  32. LocalAddr string `yaml:"localaddr"`
  33. Mod string `yaml:"mod"`
  34. Name string `yaml:"name"`
  35. UseETCD bool `yaml:"useetcd"`
  36. }
  37. type ETCD struct {
  38. Addrs []string `yaml:"addrs"`
  39. Timeout int `yaml:"timeout"`
  40. LockLease int64 `yaml:"locklease"`
  41. ServiceLease int64 `yaml:"servicelease"`
  42. }
  43. func InitConfig() (err error) {
  44. baseDir, err := utils.GetCurrentPath("conf")
  45. fmt.Println("conf:", baseDir)
  46. if err != nil {
  47. return
  48. }
  49. viper.SetConfigName("app_config")
  50. viper.SetConfigType("yaml")
  51. viper.AddConfigPath(baseDir)
  52. if err = viper.ReadInConfig(); err != nil {
  53. return
  54. }
  55. if err = viper.Unmarshal(&AppConfig); err != nil {
  56. return
  57. }
  58. return nil
  59. }