config.go 521 B

12345678910111213141516171819202122232425262728
  1. package db
  2. import (
  3. "time"
  4. )
  5. // Config config
  6. type Config struct {
  7. Driver string
  8. DNS string
  9. MaxOpenConns int
  10. MaxIdle int
  11. MaxIdleTime time.Duration
  12. MaxLifeTime time.Duration
  13. }
  14. // SetConfig set
  15. func SetConfig(cfg Config) {
  16. config.Driver = cfg.Driver
  17. config.DNS = cfg.DNS
  18. config.MaxOpenConns = cfg.MaxOpenConns
  19. config.MaxIdle = cfg.MaxIdle
  20. config.MaxIdleTime = cfg.MaxIdleTime * time.Second
  21. config.MaxLifeTime = cfg.MaxLifeTime * time.Second
  22. defaultDB = &DB{Driver: config.Driver}
  23. }