mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
61 lines
1.4 KiB
Go
61 lines
1.4 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"`
|
|
CookieSecret string `yaml:"cookieSecret"`
|
|
}
|
|
|
|
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",
|
|
"cookieSecret": "COOKIE_SECRET",
|
|
}
|
|
|
|
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
|
|
}
|