From 7f96d0ed6a48d2113fa491ab7fe46db40d746366 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Fri, 12 Jun 2015 14:17:18 -0700 Subject: [PATCH] Pull WithDefaults from collectd and openTSDB This pattern, which is present in Graphite, is not needed for collectd and openTSDB. --- services/collectd/config.go | 25 ------------------------- services/collectd/service.go | 2 +- services/opentsdb/config.go | 19 ------------------- services/opentsdb/service.go | 11 ++++------- 4 files changed, 5 insertions(+), 52 deletions(-) diff --git a/services/collectd/config.go b/services/collectd/config.go index ed9d69ca39..3129c3378d 100644 --- a/services/collectd/config.go +++ b/services/collectd/config.go @@ -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 -} diff --git a/services/collectd/service.go b/services/collectd/service.go index 76ba371a8c..71efa90b69 100644 --- a/services/collectd/service.go +++ b/services/collectd/service.go @@ -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), } diff --git a/services/opentsdb/config.go b/services/opentsdb/config.go index 0e0ddf0f7c..324002b720 100644 --- a/services/opentsdb/config.go +++ b/services/opentsdb/config.go @@ -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 -} diff --git a/services/opentsdb/service.go b/services/opentsdb/service.go index dc10d968eb..0c60aec85a 100644 --- a/services/opentsdb/service.go +++ b/services/opentsdb/service.go @@ -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), }