config.go 822 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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() (err error) {
  16. if _, err = toml.DecodeFile(confPath, &Conf); err != nil {
  17. panic(err)
  18. }
  19. return
  20. }
  21. type Config struct {
  22. // Log *log.Config `toml:"log"`
  23. DB *MySQLConfig `toml:"db"`
  24. Listen string `toml:"listen"`
  25. Log *log.Config `toml:"log"`
  26. }
  27. type MySQLConfig struct {
  28. DSN string `toml:"dsn"`
  29. Active int `toml:"active"`
  30. Idle int `toml:"idle"`
  31. IdleTimeout time.Duration `toml:"idle_timeout"`
  32. }
  33. type Conifg struct {
  34. Level string `toml:"level"`
  35. File string `toml:"file"`
  36. Stdout bool `toml:"stdout"`
  37. }