From a127f4c5d6c94190deefba5f27f48d16c612e376 Mon Sep 17 00:00:00 2001 From: Himanshu Date: Tue, 26 Jul 2016 21:08:30 +0530 Subject: [PATCH] removing config pkg Get() method and making it use a different Get method --- app/DAL/clients/crowdy.go | 4 ++-- app/DAL/clients/email.go | 2 +- app/DAL/clients/mgo.go | 4 ++-- app/DAL/clients/postgres/gorp.go | 8 ++++---- app/DAL/clients/s3.go | 4 ++-- app/api/auther/auth.go | 2 +- app/api/builder.go | 4 ++-- app/config/config_keys.go | 10 ---------- app/config/config_test.go | 4 ++-- app/plog/error.go | 2 +- app/services/flu_svc/flu_output/flu_monitor.go | 10 +++++----- app/services/image_svc/upload.go | 4 ++-- experiments/sqlx.go | 2 +- 13 files changed, 25 insertions(+), 35 deletions(-) diff --git a/app/DAL/clients/crowdy.go b/app/DAL/clients/crowdy.go index b843db6ec4d0..b4ef4ce2c370 100644 --- a/app/DAL/clients/crowdy.go +++ b/app/DAL/clients/crowdy.go @@ -12,9 +12,9 @@ import ( "github.com/crowdflux/angel/app/models" ) -var crowdyBaseApiUrl = config.Get(config.CROWDY_BASE_API) +var crowdyBaseApiUrl = config.CROWDY_BASE_API.Get() var pushFluUrl = crowdyBaseApiUrl + "/crowdsourcing_gateway?action=add_flu" -var authkey = config.Get(config.CROWDY_AUTH_KEY) +var authkey = config.CROWDY_AUTH_KEY.Get() func GetCrowdyClient() *crowdyClient { return &crowdyClient{} diff --git a/app/DAL/clients/email.go b/app/DAL/clients/email.go index cfda22791e83..f77931e1926e 100644 --- a/app/DAL/clients/email.go +++ b/app/DAL/clients/email.go @@ -7,6 +7,6 @@ import ( // Donot use this for now func NewSendGridClient() *sendgrid.SGClient { - client := sendgrid.NewSendGridClientWithApiKey(config.Get(config.SENDGRID_API_KEY)) + client := sendgrid.NewSendGridClientWithApiKey(config.SENDGRID_API_KEY.Get()) return client } diff --git a/app/DAL/clients/mgo.go b/app/DAL/clients/mgo.go index d62bab5da2ec..1366898a1611 100644 --- a/app/DAL/clients/mgo.go +++ b/app/DAL/clients/mgo.go @@ -13,13 +13,13 @@ func init() { func initMongoDb() *mgo.Database { - session, err := mgo.Dial(config.Get(config.MONGO_HOST)) + session, err := mgo.Dial(config.MONGO_HOST.Get()) if err != nil { panic(err) } //session.SetMode(mgo.Monotonic, true) - db := session.DB(config.Get(config.MONGO_DB_NAME)) + db := session.DB(config.MONGO_DB_NAME.Get()) return db } diff --git a/app/DAL/clients/postgres/gorp.go b/app/DAL/clients/postgres/gorp.go index 51fe6c5a6b9a..00b4d5b55cfa 100644 --- a/app/DAL/clients/postgres/gorp.go +++ b/app/DAL/clients/postgres/gorp.go @@ -17,10 +17,10 @@ func init() { func initGorpClient() *gorp.DbMap { - dbName := config.Get(config.PG_DATABASE_NAME) - username := config.Get(config.PG_USERNAME) - host := config.Get(config.PG_HOST) - password := config.Get(config.PG_PASSWORD) + dbName := config.PG_DATABASE_NAME.Get() + username := config.PG_USERNAME.Get() + host := config.PG_HOST.Get() + password := config.PG_PASSWORD.Get() // connect to db using standard Go database/sql API // use whatever database/sql driver you wish diff --git a/app/DAL/clients/s3.go b/app/DAL/clients/s3.go index ba99738c3484..920e94f4e5f4 100644 --- a/app/DAL/clients/s3.go +++ b/app/DAL/clients/s3.go @@ -24,8 +24,8 @@ func init() { func initS3() *s3manager.Uploader { awsConfig := aws.NewConfig(). - WithRegion(config.Get(config.AWS_REGION)). - WithCredentials(credentials.NewStaticCredentials(config.Get(config.AWS_ACCESS_ID), config.Get(config.AWS_SECRET_KEY), "")) + WithRegion(config.AWS_REGION.Get()). + WithCredentials(credentials.NewStaticCredentials(config.AWS_ACCESS_ID.Get(), config.AWS_SECRET_KEY.Get(), "")) uploader = s3manager.NewUploader(session.New(awsConfig)) uploader.Concurrency = 60 diff --git a/app/api/auther/auth.go b/app/api/auther/auth.go index 34fec7284fa2..c5d1d290a139 100644 --- a/app/api/auther/auth.go +++ b/app/api/auther/auth.go @@ -50,4 +50,4 @@ func (a auther) Check(id uuid.UUID, key string) bool { //--------------------------------------------------------------------------------// -var StdProdAuther = auther{[]byte(config.Get(config.AUTHER_PLAYMENT_SECRET))} +var StdProdAuther = auther{[]byte(config.AUTHER_PLAYMENT_SECRET.Get())} diff --git a/app/api/builder.go b/app/api/builder.go index a1153ed5c002..d43aba0b34a7 100644 --- a/app/api/builder.go +++ b/app/api/builder.go @@ -45,8 +45,8 @@ func Build() { ValidateHeaders: false, })) - fmt.Println(config.Get(config.DOWNLOAD_PATH)) - r.StaticFS("/downloadedfiles", http.Dir(config.Get(config.DOWNLOAD_PATH))) + fmt.Println(config.DOWNLOAD_PATH.Get()) + r.StaticFS("/downloadedfiles", http.Dir(config.DOWNLOAD_PATH.Get())) //Api prefix diff --git a/app/config/config_keys.go b/app/config/config_keys.go index cb725563af1a..ad8a4c536d46 100644 --- a/app/config/config_keys.go +++ b/app/config/config_keys.go @@ -49,17 +49,7 @@ const ( ) // Gets the value for given key from the config file. -// It accepts only configKey type, which is private, so -// only the above consts can be passed // It panics no configuration value is present -func Get(c configKey) string { - val := configProvider.GetString(string(c)) - if val == "" { - panic(errors.New("Configuration value not found [" + string(c) + "]")) - } - return val -} - func (c configKey) Get() string { val := configProvider.GetString(string(c)) if val == "" { diff --git a/app/config/config_test.go b/app/config/config_test.go index cf3f173ffda2..9f80ba7f4d4b 100644 --- a/app/config/config_test.go +++ b/app/config/config_test.go @@ -10,13 +10,13 @@ import ( func Test(t *testing.T) { - s := config.Get(config.PG_HOST) + s := config.PG_HOST.Get() assert.EqualValues(t, "localhost", s) } func ExampleGet() { - baseApi := config.Get(config.BASE_API_URL) + baseApi := config.BASE_API_URL.Get() fmt.Println(baseApi) // Output: localhost:8999/api diff --git a/app/plog/error.go b/app/plog/error.go index 6c5594efebec..56d0e9c3c0f7 100644 --- a/app/plog/error.go +++ b/app/plog/error.go @@ -35,7 +35,7 @@ func ErrorMail(tag string, err error, args ...interface{}) { go func() { - cl := sendgrid.NewSendGridClientWithApiKey(config.Get(config.SENDGRID_API_KEY)) + cl := sendgrid.NewSendGridClientWithApiKey(config.SENDGRID_API_KEY.Get()) mail := sendgrid.NewMail() diff --git a/app/services/flu_svc/flu_output/flu_monitor.go b/app/services/flu_svc/flu_output/flu_monitor.go index c4ec0e716013..a054c1053bbf 100644 --- a/app/services/flu_svc/flu_output/flu_monitor.go +++ b/app/services/flu_svc/flu_output/flu_monitor.go @@ -27,12 +27,12 @@ var retryCount = make(map[uuid.UUID]int) var mutex = &sync.RWMutex{} var dbLogger = feed_line_repo.StdLogger -var retryTimePeriod = time.Duration(utilities.GetInt(config.Get(config.RETRY_TIME_PERIOD))) * time.Millisecond +var retryTimePeriod = time.Duration(utilities.GetInt(config.RETRY_TIME_PERIOD.Get())) * time.Millisecond -var defaultFluThresholdCount = utilities.GetInt(config.Get(config.DEFAULT_FLU_THRESHOLD_COUNT)) -var fluThresholdDuration = int64(utilities.GetInt(config.Get(config.FLU_THRESHOLD_DURATION))) -var monitorTimePeriod = time.Duration(utilities.GetInt(config.Get(config.MONITOR_TIME_PERIOD))) * time.Millisecond -var retryThreshold = utilities.GetInt(config.Get(config.FLU_RETRY_THRESHOLD)) +var defaultFluThresholdCount = utilities.GetInt(config.DEFAULT_FLU_THRESHOLD_COUNT.Get()) +var fluThresholdDuration = int64(utilities.GetInt(config.FLU_THRESHOLD_DURATION.Get())) +var monitorTimePeriod = time.Duration(utilities.GetInt(config.MONITOR_TIME_PERIOD.Get())) * time.Millisecond +var retryThreshold = utilities.GetInt(config.FLU_RETRY_THRESHOLD.Get()) type feedLineValue struct { maxFluSize int diff --git a/app/services/image_svc/upload.go b/app/services/image_svc/upload.go index 317180e03156..6a8ebbe161f0 100644 --- a/app/services/image_svc/upload.go +++ b/app/services/image_svc/upload.go @@ -16,8 +16,8 @@ func uploadToS3(img io.ReadCloser) { defer img.Close() awsConfig := aws.NewConfig(). - WithRegion(config.Get(config.AWS_REGION)). - WithCredentials(credentials.NewStaticCredentials(config.Get(config.AWS_ACCESS_ID), config.Get(config.AWS_SECRET_KEY), "")) + WithRegion(config.AWS_REGION.Get()). + WithCredentials(credentials.NewStaticCredentials(config.AWS_ACCESS_ID.Get(), config.AWS_SECRET_KEY.Get(), "")) uploader := s3manager.NewUploader(session.New(awsConfig)) diff --git a/experiments/sqlx.go b/experiments/sqlx.go index 703e4307efb3..5599bd9c12bf 100644 --- a/experiments/sqlx.go +++ b/experiments/sqlx.go @@ -16,7 +16,7 @@ func initSQLxClient() *sqlx.DB { // connect to db using standard Go database/sql API // use whatever database/sql driver you wish - dbName := config.Get(config.PG_DATABASE_NAME) + dbName := config.PG_DATABASE_NAME.Get() db := sqlx.MustConnect("postgres", "dbname="+dbName+" user=postgres password=postgres host=localhost sslmode=disable") return db