config.go 778 B

1234567891011121314151617181920212223242526272829
  1. package database
  2. import "git.linuxforward.com/byom/byom-golang-lib/pkg/errors"
  3. // Config holds the database configuration
  4. type Config struct {
  5. Path string `yaml:"path"`
  6. MaxOpenConns int `yaml:"max_open_conns"`
  7. MaxIdleConns int `yaml:"max_idle_conns"`
  8. ConnMaxLifetime int `yaml:"conn_max_lifetime"`
  9. Pragmas []string `yaml:"pragmas"`
  10. }
  11. // Validate implements the config.Validator interface
  12. func (c *Config) Validate() error {
  13. if c.Path == "" {
  14. return errors.NewConfigError("database.path", errors.ErrInvalidInput)
  15. }
  16. if c.MaxOpenConns == 0 {
  17. c.MaxOpenConns = 1 // SQLite recommendation
  18. }
  19. if c.MaxIdleConns == 0 {
  20. c.MaxIdleConns = 1
  21. }
  22. if c.ConnMaxLifetime == 0 {
  23. c.ConnMaxLifetime = 300 // 5 minutes
  24. }
  25. return nil
  26. }