Set openTSDB defaults in service
parent
3273db25f2
commit
e294db3c49
|
@ -30,3 +30,22 @@ func NewConfig() Config {
|
||||||
ConsistencyLevel: DefaultConsistencyLevel,
|
ConsistencyLevel: DefaultConsistencyLevel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithDefaults takes the given config and returns a new config with any required
|
||||||
|
// default values set.
|
||||||
|
func (c *Config) WithDefaults() *Config {
|
||||||
|
d := *c
|
||||||
|
if d.BindAddress == "" {
|
||||||
|
d.BindAddress = DefaultBindAddress
|
||||||
|
}
|
||||||
|
if d.Database == "" {
|
||||||
|
d.Database = DefaultDatabase
|
||||||
|
}
|
||||||
|
if d.RetentionPolicy == "" {
|
||||||
|
d.RetentionPolicy = DefaultRetentionPolicy
|
||||||
|
}
|
||||||
|
if d.ConsistencyLevel == "" {
|
||||||
|
d.ConsistencyLevel = DefaultConsistencyLevel
|
||||||
|
}
|
||||||
|
return &d
|
||||||
|
}
|
||||||
|
|
|
@ -44,16 +44,19 @@ type Service struct {
|
||||||
|
|
||||||
// NewService returns a new instance of Service.
|
// NewService returns a new instance of Service.
|
||||||
func NewService(c Config) (*Service, error) {
|
func NewService(c Config) (*Service, error) {
|
||||||
consistencyLevel, err := cluster.ParseConsistencyLevel(c.ConsistencyLevel)
|
// Use defaults where necessary.
|
||||||
|
d := c.WithDefaults()
|
||||||
|
|
||||||
|
consistencyLevel, err := cluster.ParseConsistencyLevel(d.ConsistencyLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &Service{
|
s := &Service{
|
||||||
err: make(chan error),
|
err: make(chan error),
|
||||||
BindAddress: c.BindAddress,
|
BindAddress: d.BindAddress,
|
||||||
Database: c.Database,
|
Database: d.Database,
|
||||||
RetentionPolicy: c.RetentionPolicy,
|
RetentionPolicy: d.RetentionPolicy,
|
||||||
ConsistencyLevel: consistencyLevel,
|
ConsistencyLevel: consistencyLevel,
|
||||||
Logger: log.New(os.Stderr, "[opentsdb] ", log.LstdFlags),
|
Logger: log.New(os.Stderr, "[opentsdb] ", log.LstdFlags),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue