config.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package config
  2. import (
  3. "time"
  4. "github.com/BurntSushi/toml"
  5. "kpt.xdmy/pkg/log"
  6. "kpt.xdmy/pkg/setting"
  7. )
  8. var (
  9. confPath string
  10. Conf = &Config{}
  11. )
  12. type Http struct {
  13. TimeOut time.Duration `toml:"timeout"`
  14. SapName string `toml:"sapname"`
  15. SapPwd string `toml:"sappwd"`
  16. SrmName string `toml:"srmname"`
  17. SrmPwd string `toml:"srmpwd"`
  18. Routing string `toml:"routing"`
  19. }
  20. type Config struct {
  21. DB *MySQLConfig `toml:"db"`
  22. Http *Http `toml:"http"`
  23. }
  24. type MySQLConfig struct {
  25. DSN string `toml:"dsn"`
  26. Active int `toml:"active"`
  27. Idle int `toml:"idle"`
  28. IdleTimeout time.Duration `toml:"idle_timeout"`
  29. }
  30. // func init() {
  31. // flag.StringVar(&confPath, "tconf", "", "default config path")
  32. // }
  33. func Init(p string) (err error) {
  34. if p != "" {
  35. confPath = p
  36. } else {
  37. confPath, err = setting.GetCurrentPath()
  38. }
  39. confPath += "conf/conf.toml"
  40. if _, err = toml.DecodeFile(confPath, &Conf); err != nil {
  41. log.Error("config Init : %v", err)
  42. return
  43. }
  44. return
  45. }