package clickhouse import ( "fmt" "git.beejay.kim/tool/service/config" "strings" ) type Config struct { Username string `json:"username" yaml:"username"` Password string `json:"password" yaml:"password"` Host string `json:"host" yaml:"host"` Port int `json:"port" yaml:"port"` Database string `json:"database" yaml:"database"` Params params `json:"params" yaml:"params"` } func (c Config) Invalidate() error { if strings.TrimSpace(c.Username) == "" { return fmt.Errorf("`database.username` must not be an empty string") } if strings.TrimSpace(c.Host) == "" { c.Host = "localhost" } if c.Port < 1 { c.Port = 9000 } if strings.TrimSpace(c.Database) == "" { return fmt.Errorf("`database.database` must not be an empty string") } return config.Invalidate(c) } type params struct { Timeout int `json:"timeout" yaml:"timeout"` ReadTimeout int `json:"read_timeout" yaml:"read-timeout"` WriteTimeout int `json:"write_timeout" yaml:"write-timeout"` } func (p params) Invalidate() error { if p.Timeout < 1 { return fmt.Errorf("`database.params.timeout` must not be at least 1") } if p.ReadTimeout < 1 { return fmt.Errorf("`database.params.read-timeout` must not be at least 1") } if p.WriteTimeout < 1 { return fmt.Errorf("`database.params.write-timeout` must not be at least 1") } return config.Invalidate(&p) }