package config import ( "strings" "git.defalsify.org/vise.git/logging" "git.grassecon.net/grassrootseconomics/visedriver/env" ) var ( defaultLanguage = "eng" languages []string ) var ( DbConn string DefaultLanguage string Languages []string ) func setLanguage() error { defaultLanguage = env.GetEnv("DEFAULT_LANGUAGE", defaultLanguage) languages = strings.Split(env.GetEnv("LANGUAGES", defaultLanguage), ",") haveDefaultLanguage := false for i, v := range languages { languages[i] = strings.ReplaceAll(v, " ", "") if languages[i] == defaultLanguage { haveDefaultLanguage = true } } if !haveDefaultLanguage { languages = append([]string{defaultLanguage}, languages...) } return nil } func setConn() error { DbConn = env.GetEnv("DB_CONN", "") return nil } // LoadConfig initializes the configuration values after environment variables are loaded. func LoadConfig() error { if err := setLanguage(); err != nil { return err } if err := setConn(); err != nil { return err } DefaultLanguage = defaultLanguage Languages = languages // Create and use reporter logger := logging.NewVanilla().WithDomain("config") reporter := NewReporter(logger) reporter.AddValue("CUSTOM_SETTING", func() string { return env.GetEnv("CUSTOM_SETTING", "default") }, false) reporter.Report("INFO") return nil }