config.go 945 B

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