config.go 1.0 KB

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