config.go 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package config
  2. import (
  3. "flag"
  4. "time"
  5. "github.com/BurntSushi/toml"
  6. "kpt.notice/pkg/log"
  7. )
  8. var (
  9. confPath string
  10. Conf = &Config{}
  11. )
  12. func init() {
  13. flag.StringVar(&confPath, "conf", "conf.toml", "default config path")
  14. }
  15. func Init(p string) (err error) {
  16. if p != "" {
  17. confPath = p
  18. }
  19. if _, err = toml.DecodeFile(confPath, &Conf); err != nil {
  20. panic(err)
  21. }
  22. return
  23. }
  24. type Config struct {
  25. // Log *log.Config `toml:"log"`
  26. DB *MySQLConfig `toml:"db"`
  27. Listen string `toml:"listen"`
  28. Log *log.Config `toml:"log"`
  29. Env string `toml:"env"`
  30. }
  31. type MySQLConfig struct {
  32. DSN string `toml:"dsn"`
  33. Active int `toml:"active"`
  34. Idle int `toml:"idle"`
  35. IdleTimeout time.Duration `toml:"idle_timeout"`
  36. }
  37. type Conifg struct {
  38. Level string `toml:"level"`
  39. File string `toml:"file"`
  40. Stdout bool `toml:"stdout"`
  41. }