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
2017-08-19 22:04:41 -07:00

59 lines
1.3 KiB
Go

package config
import (
"strings"
"github.com/spf13/viper"
)
const FileName = "podsync"
type AppConfig struct {
YouTubeApiKey string `yaml:"youtubeApiKey"`
VimeoApiKey string `yaml:"vimeoApiKey"`
PatreonClientId string `yaml:"patreonClientId"`
PatreonSecret string `yaml:"patreonSecret"`
PostgresConnectionURL string `yaml:"postgresConnectionUrl"`
RedisURL string `yaml:"redisUrl"`
}
func ReadConfiguration() (cfg *AppConfig, err error) {
viper.SetConfigName(FileName)
// Configuration file
viper.AddConfigPath(".")
viper.AddConfigPath("/app/config/")
// Env variables
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
envmap := map[string]string{
"youtubeApiKey": "YOUTUBE_API_KEY",
"vimeoApiKey": "VIMEO_API_KEY",
"patreonClientId": "PATREON_CLIENT_ID",
"patreonSecret": "PATREON_SECRET",
"postgresConnectionUrl": "POSTGRES_CONNECTION_URL",
"redisUrl": "REDIS_CONNECTION_URL",
}
for k, v := range envmap {
viper.BindEnv(k, v)
}
err = viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return
}
// Ignore file not found error
err = nil
}
cfg = &AppConfig{}
viper.Unmarshal(cfg)
return
}