Ensure collectd uses defaults with partial config
parent
f28362d161
commit
44033778f5
|
@ -42,3 +42,28 @@ func NewConfig() Config {
|
|||
TypesDB: DefaultTypesDB,
|
||||
}
|
||||
}
|
||||
|
||||
// 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.BatchSize == 0 {
|
||||
d.BatchSize = DefaultBatchSize
|
||||
}
|
||||
if d.BatchDuration == 0 {
|
||||
d.BatchDuration = DefaultBatchDuration
|
||||
}
|
||||
if d.TypesDB == "" {
|
||||
d.TypesDB = DefaultTypesDB
|
||||
}
|
||||
return &d
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ type Service struct {
|
|||
// NewService returns a new instance of the collectd service.
|
||||
func NewService(c Config) *Service {
|
||||
s := &Service{
|
||||
Config: &c,
|
||||
Config: c.WithDefaults(),
|
||||
Logger: log.New(os.Stderr, "[collectd] ", log.LstdFlags),
|
||||
err: make(chan error),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue