1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00
mxpv-podsync/pkg/config/config.go

73 lines
2.0 KiB
Go
Raw Normal View History

2017-07-31 18:02:12 -07:00
package config
import (
"strings"
"github.com/spf13/viper"
)
const FileName = "podsync"
type AppConfig struct {
2019-01-06 21:36:42 -08:00
YouTubeAPIKey string `yaml:"youtubeApiKey"`
VimeoAPIKey string `yaml:"vimeoApiKey"`
PatreonClientID string `yaml:"patreonClientId"`
2018-12-08 14:26:50 -08:00
PatreonSecret string `yaml:"patreonSecret"`
PatreonRedirectURL string `yaml:"patreonRedirectUrl"`
PatreonWebhooksSecret string `json:"patreonWebhooksSecret"`
PostgresConnectionURL string `yaml:"postgresConnectionUrl"`
CookieSecret string `yaml:"cookieSecret"`
2018-12-08 16:21:08 -08:00
AWSAccessKey string `yaml:"awsAccessKey"`
AWSAccessSecret string `yaml:"awsAccessSecret"`
2018-12-08 14:26:50 -08:00
DynamoFeedsTableName string `yaml:"dynamoFeedsTableName"`
DynamoPledgesTableName string `yaml:"dynamoPledgesTableName"`
2019-03-11 21:23:36 -07:00
RedisURL string `yaml:"redisUrl"`
2017-07-31 18:02:12 -07:00
}
2019-01-07 20:47:59 -08:00
func ReadConfiguration() (*AppConfig, error) {
2017-07-31 18:02:12 -07:00
viper.SetConfigName(FileName)
// Configuration file
viper.AddConfigPath(".")
viper.AddConfigPath("/app/config/")
// Env variables
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
envmap := map[string]string{
2018-12-08 14:26:50 -08:00
"youtubeApiKey": "YOUTUBE_API_KEY",
"vimeoApiKey": "VIMEO_API_KEY",
"patreonClientId": "PATREON_CLIENT_ID",
"patreonSecret": "PATREON_SECRET",
"patreonRedirectUrl": "PATREON_REDIRECT_URL",
"patreonWebhooksSecret": "PATREON_WEBHOOKS_SECRET",
"postgresConnectionUrl": "POSTGRES_CONNECTION_URL",
"redisUrl": "REDIS_CONNECTION_URL",
"cookieSecret": "COOKIE_SECRET",
2018-12-08 16:21:08 -08:00
"awsAccessKey": "AWS_ACCESS_KEY",
"awsAccessSecret": "AWS_ACCESS_SECRET",
2018-12-08 14:26:50 -08:00
"dynamoFeedsTableName": "DYNAMO_FEEDS_TABLE_NAME",
"dynamoPledgesTableName": "DYNAMO_PLEDGES_TABLE_NAME",
2017-07-31 18:02:12 -07:00
}
for k, v := range envmap {
viper.BindEnv(k, v)
}
2019-01-07 20:47:59 -08:00
err := viper.ReadInConfig()
2017-07-31 18:02:12 -07:00
if err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
2019-01-07 20:47:59 -08:00
return nil, err
2017-07-31 18:02:12 -07:00
}
}
2019-01-07 20:47:59 -08:00
cfg := &AppConfig{}
if err := viper.Unmarshal(cfg); err != nil {
return nil, err
}
2017-07-31 18:02:12 -07:00
2019-01-07 20:47:59 -08:00
return cfg, nil
2017-07-31 18:02:12 -07:00
}