Pull WithDefaults from collectd and openTSDB

This pattern, which is present in Graphite, is not needed for collectd
and openTSDB.
pull/2974/head
Philip O'Toole 2015-06-12 14:17:18 -07:00
parent c622d6a340
commit 7f96d0ed6a
4 changed files with 5 additions and 52 deletions

View File

@ -42,28 +42,3 @@ 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
}

View File

@ -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.WithDefaults(),
Config: &c,
Logger: log.New(os.Stderr, "[collectd] ", log.LstdFlags),
err: make(chan error),
}

View File

@ -30,22 +30,3 @@ func NewConfig() Config {
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
}

View File

@ -47,19 +47,16 @@ type Service struct {
// NewService returns a new instance of Service.
func NewService(c Config) (*Service, error) {
// Use defaults where necessary.
d := c.WithDefaults()
consistencyLevel, err := cluster.ParseConsistencyLevel(d.ConsistencyLevel)
consistencyLevel, err := cluster.ParseConsistencyLevel(c.ConsistencyLevel)
if err != nil {
return nil, err
}
s := &Service{
err: make(chan error),
BindAddress: d.BindAddress,
Database: d.Database,
RetentionPolicy: d.RetentionPolicy,
BindAddress: c.BindAddress,
Database: c.Database,
RetentionPolicy: c.RetentionPolicy,
ConsistencyLevel: consistencyLevel,
Logger: log.New(os.Stderr, "[opentsdb] ", log.LstdFlags),
}