feat: read config from env

This commit is contained in:
Johan Siebens
2022-10-19 08:09:34 +02:00
parent cf75b9240c
commit 43167c1fae
+14
View File
@@ -1,6 +1,7 @@
package config
import (
"encoding/base64"
"fmt"
"github.com/caarlos0/env/v6"
"github.com/caddyserver/certmagic"
@@ -64,6 +65,19 @@ func LoadConfig(path string) (*Config, error) {
}
}
envCfgB64 := os.Getenv("IONSCALE_CONFIG_BASE64")
if len(envCfgB64) != 0 {
b, err := base64.RawStdEncoding.DecodeString(envCfgB64)
if err != nil {
return nil, err
}
// merge env configuration on top of the default/file configuration
if err := yaml.Unmarshal(b, cfg); err != nil {
return nil, err
}
}
envCfg := &Config{}
if err := env.Parse(envCfg, env.Options{Prefix: "IONSCALE_"}); err != nil {
return nil, err