conf.go 647 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package configs
  2. import (
  3. "flag"
  4. "github.com/BurntSushi/toml"
  5. "github.com/hwholiday/gid/v2/library/database/mysql"
  6. "github.com/hwholiday/gid/v2/library/log"
  7. )
  8. var (
  9. confPath string
  10. Conf = new(Config)
  11. )
  12. type Config struct {
  13. Development bool
  14. SnowFlakeId int64
  15. Etcd []string
  16. Log *log.Options
  17. Mysql *mysql.Config
  18. Server *Srv
  19. }
  20. type Srv struct {
  21. Addr string
  22. }
  23. func init() {
  24. flag.StringVar(&confPath, "conf", "./gid.toml", "default config path")
  25. }
  26. func Init() error {
  27. return local()
  28. }
  29. func local() (err error) {
  30. _, err = toml.DecodeFile(confPath, &Conf)
  31. Conf.Mysql.Debug = Conf.Development
  32. return
  33. }