Allow configuration overriding with environment variables
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/caarlos0/env/v6"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@ -33,32 +34,32 @@ func NewFromFile(filepath string) (*Config, error) {
|
||||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
Address string `yaml:"address"`
|
||||
CookieAuthenticationKey string `yaml:"cookieAuthenticationKey"`
|
||||
CookieEncryptionKey string `yaml:"cookieEncryptionKey"`
|
||||
TokenSigningKey string `yaml:"tokenSigningKey"`
|
||||
TokenEncryptionKey string `yaml:"tokenEncryptionKey"`
|
||||
BasePublicURL string `yaml:"basePublicUrl"`
|
||||
CookieMaxAge int `yaml:"cookieMaxAge"`
|
||||
TemplateDir string `yaml:"templateDir"`
|
||||
PublicDir string `yaml:"publicDir"`
|
||||
PublicAddress string `yaml:"publicAddress"`
|
||||
PublicScheme string `yaml:"publicScheme"`
|
||||
Address string `yaml:"address" env:"HTTP_ADDRESS"`
|
||||
CookieAuthenticationKey string `yaml:"cookieAuthenticationKey" env:"HTTP_COOKIE_AUTHENTICATION_KEY"`
|
||||
CookieEncryptionKey string `yaml:"cookieEncryptionKey" env:"HTTP_COOKIE_ENCRYPTION_KEY"`
|
||||
TokenSigningKey string `yaml:"tokenSigningKey" env:"HTTP_TOKEN_SIGNING_KEY"`
|
||||
TokenEncryptionKey string `yaml:"tokenEncryptionKey" env:"HTTP_TOKEN_ENCRYPTION_KEY"`
|
||||
BasePublicURL string `yaml:"basePublicUrl" env:"HTTP_BASE_PUBLIC_URL"`
|
||||
CookieMaxAge int `yaml:"cookieMaxAge" env:"HTTP_COOKIE_MAX_AGE"`
|
||||
TemplateDir string `yaml:"templateDir" env:"HTTP_TEMPLATE_DIR"`
|
||||
PublicDir string `yaml:"publicDir" env:"HTTP_PUBLIC_DIR"`
|
||||
PublicAddress string `yaml:"publicAddress" env:"HTTP_PUBLIC_ADDRESS"`
|
||||
PublicScheme string `yaml:"publicScheme" env:"HTTP_PUBLIC_SCHEME"`
|
||||
}
|
||||
|
||||
type SMTPConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
UseStartTLS bool `yaml:"useStartTLS"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
InsecureSkipVerify bool `yaml:"insecureSkipVerify"`
|
||||
SenderAddress string `yaml:"senderAddress"`
|
||||
SenderName string `yaml:"senderName"`
|
||||
Host string `yaml:"host" env:"SMTP_HOST"`
|
||||
Port int `yaml:"port" env:"SMTP_PORT"`
|
||||
UseStartTLS bool `yaml:"useStartTLS" env:"SMTP_USE_START_TLS"`
|
||||
User string `yaml:"user" env:"SMTP_USER"`
|
||||
Password string `yaml:"password" env:"SMTP_PASSWORD"`
|
||||
InsecureSkipVerify bool `yaml:"insecureSkipVerify" env:"SMTP_INSECURE_SKIP_VERIFY"`
|
||||
SenderAddress string `yaml:"senderAddress" env:"SMTP_SENDER_ADDRESS"`
|
||||
SenderName string `yaml:"senderName" env:"SMTP_SENDER_NAME"`
|
||||
}
|
||||
|
||||
type HydraConfig struct {
|
||||
BaseURL string `yaml:"baseURL"`
|
||||
BaseURL string `yaml:"baseURL" env:"HYDRA_BASE_URL"`
|
||||
}
|
||||
|
||||
func NewDumpDefault() *Config {
|
||||
@ -106,3 +107,11 @@ func Dump(config *Config, w io.Writer) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func WithEnvironment(conf *Config) error {
|
||||
if err := env.Parse(conf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user