Browse Source

add config env variables.

master
Gisle Aune 3 months ago
parent
commit
3ffe1d7816
  1. 25
      internal/config/config.go

25
internal/config/config.go

@ -5,6 +5,7 @@ import (
"errors"
"log"
"os"
"strconv"
"strings"
"sync"
@ -51,6 +52,27 @@ type Wiki struct {
URL string `json:"url" yaml:"url"`
}
func (config *Config) LoadEnv() {
config.Wiki.URL = os.Getenv("RPDATA_WIKI_URL")
config.Space.Enabled = os.Getenv("RPDATA_SPACE_ENABLED") == "true"
config.Space.Host = os.Getenv("RPDATA_SPACE_HOST")
config.Space.AccessKey = os.Getenv("RPDATA_SPACE_ACCESS_KEY")
config.Space.SecretKey = os.Getenv("RPDATA_SPACE_SECRET_KEY")
config.Space.Bucket = os.Getenv("RPDATA_SPACE_BUCKET")
config.Space.MaxSize, _ = strconv.ParseInt(os.Getenv("RPDATA_SPACE_MAX_SIZE"), 10, 64)
config.Space.Root = os.Getenv("RPDATA_SPACE_ROOT")
config.Space.URLRoot = os.Getenv("RPDATA_SPACE_URL_ROOT")
config.Database.Driver = os.Getenv("RPDATA_DATABASE_DRIVER")
config.Database.Host = os.Getenv("RPDATA_DATABASE_HOST")
config.Database.Port, _ = strconv.Atoi(os.Getenv("RPDATA_DATABASE_PORT"))
config.Database.Db = os.Getenv("RPDATA_DATABASE_DB")
config.Database.Username = os.Getenv("RPDATA_DATABASE_USERNAME")
config.Database.Password = os.Getenv("RPDATA_DATABASE_PASSWORD")
config.Database.Mechanism = os.Getenv("RPDATA_DATABASE_MECHANISM")
config.Database.RestoreIDs = os.Getenv("RPDATA_DATABASE_RESTORE_IDS") == "true"
config.Database.SSL = os.Getenv("RPDATA_DATABASE_SSL") == "true"
}
// Load loads config stuff
func (config *Config) Load(filename string) error {
log.Println("Trying to load config from " + filename)
@ -94,9 +116,10 @@ func Global() Config {
globalMutex.Lock()
if global == nil {
global = &Config{}
global.LoadEnv()
err := global.LoadAny("/etc/aiterp/rpdata.yaml", "/etc/aiterp/rpdata.json", "./config.yaml", "./config.json")
if err != nil {
log.Fatalln(err)
log.Println("No config files were loaded.")
}
}
globalMutex.Unlock()

Loading…
Cancel
Save