Skip to content

Commit

Permalink
Merge pull request cockroachdb#8 from crowdflux/himanshu-github
Browse files Browse the repository at this point in the history
removing config pkg Get() method
  • Loading branch information
himanshu144141 authored Jul 26, 2016
2 parents 6d68383 + a127f4c commit 1191561
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/DAL/clients/crowdy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion app/DAL/clients/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions app/DAL/clients/mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions app/DAL/clients/postgres/gorp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/DAL/clients/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/api/auther/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())}
4 changes: 2 additions & 2 deletions app/api/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions app/config/config_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
4 changes: 2 additions & 2 deletions app/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/plog/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 5 additions & 5 deletions app/services/flu_svc/flu_output/flu_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/services/image_svc/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion experiments/sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1191561

Please sign in to comment.