config.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 LiuGong struct {
  21. UserName string `toml:"username"`
  22. PassWord string `toml:"password"`
  23. Routing string `toml:"routing"`
  24. }
  25. type Config struct {
  26. DB *MySQLConfig `toml:"db"`
  27. Http *Http `toml:"http"`
  28. LiuGong *LiuGong `toml:"liugong"`
  29. }
  30. type MySQLConfig struct {
  31. DSN string `toml:"dsn"`
  32. Active int `toml:"active"`
  33. Idle int `toml:"idle"`
  34. IdleTimeout time.Duration `toml:"idle_timeout"`
  35. }
  36. // func init() {
  37. // flag.StringVar(&confPath, "tconf", "", "default config path")
  38. // }
  39. func Init(p string) (err error) {
  40. if p != "" {
  41. confPath = p
  42. } else {
  43. confPath, err = setting.GetCurrentPath()
  44. }
  45. confPath += "conf/conf.toml"
  46. if _, err = toml.DecodeFile(confPath, &Conf); err != nil {
  47. log.Error("config Init : %v", err)
  48. return
  49. }
  50. return
  51. }