Skip to content

Commit

Permalink
Merge pull request #31 from NYTimes/dynamodb
Browse files Browse the repository at this point in the history
adding a DynamoDB struct to the `config` package
  • Loading branch information
jprobinson committed Feb 23, 2016
2 parents 278ad6a + d266666 commit 993a2c9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This package contains a handful of structs meant for managing common configurati
* MySQL
* MongoDB
* Oracle
* AWS (SNS, SQS, S3)
* AWS (SNS, SQS, S3, DynamoDB)
* Kafka
* Gorilla's `securecookie`
* Gizmo Servers
Expand Down
15 changes: 13 additions & 2 deletions config/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,24 @@ type (
AWS
Bucket string `envconfig:"AWS_S3_BUCKET_NAME"`
}

// DynamoDB holds some basic info required to work with Amazon DynamoDB.
DynamoDB struct {
AWS
TableName string `envconfig:"AWS_DYNAMODB_TABLE_NAME"`
}
)

// LoadAWSFromEnv will attempt to load the AWS structs
// from environment variables. If not populated, nil
// is returned.
func LoadAWSFromEnv() (*AWS, *SNS, *SQS, *S3) {
func LoadAWSFromEnv() (*AWS, *SNS, *SQS, *S3, *DynamoDB) {
var (
aws = &AWS{}
sns = &SNS{}
sqs = &SQS{}
s3 = &S3{}
ddb = &DynamoDB{}
)
LoadEnvConfig(aws)
if aws.AccessKey == "" {
Expand All @@ -75,5 +82,9 @@ func LoadAWSFromEnv() (*AWS, *SNS, *SQS, *S3) {
if s3.Bucket == "" {
s3 = nil
}
return aws, sns, sqs, s3
LoadEnvConfig(&ddb)
if ddb.TableName == "" {
ddb = nil
}
return aws, sns, sqs, s3, ddb
}
11 changes: 6 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type (
Config struct {
Server *Server

AWS *AWS
SQS *SQS
SNS *SNS
S3 *S3
AWS *AWS
SQS *SQS
SNS *SNS
S3 *S3
DynamoDB *DynamoDB

Kafka *Kafka

Expand Down Expand Up @@ -66,7 +67,7 @@ var EnvAppName = ""
func LoadConfigFromEnv() *Config {
var app Config
LoadEnvConfig(&app)
app.AWS, app.SNS, app.SQS, app.S3 = LoadAWSFromEnv()
app.AWS, app.SNS, app.SQS, app.S3, app.DynamoDB = LoadAWSFromEnv()
app.MongoDB = LoadMongoDBFromEnv()
app.Kafka = LoadKafkaFromEnv()
app.MySQL = LoadMySQLFromEnv()
Expand Down
2 changes: 1 addition & 1 deletion config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Package config contains a handful of structs meant for managing common configura
* MySQL
* MongoDB
* Oracle
* AWS (SNS, SQS, S3)
* AWS (SNS, SQS, S3, DynamoDB)
* Kafka
* Gorilla's `securecookie`
* Gizmo Servers
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This package contains a handful of structs meant for managing common configurati
* MySQL
* MongoDB
* Oracle
* AWS (SNS, SQS, S3)
* AWS (SNS, SQS, S3, DynamoDB)
* Kafka
* Gorilla's `securecookie`
* Gizmo Servers
Expand Down

0 comments on commit 993a2c9

Please sign in to comment.