Mercurial > gemma
view config/config.go @ 142:edce32db775a vue-gettext
merge with default
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 02 Jul 2018 09:37:15 +0200 |
parents | a98a282f00e1 |
children | 5ca6f436d0b7 |
line wrap: on
line source
package config import ( "log" "os" "strconv" ) var Config = NewConfiguration() type Configuration struct { DBHost string DBPort uint DBName string DBSSLMode string JWTSignKey []byte } func NewConfiguration() *Configuration { // TODO: Load from file. return &Configuration{ DBHost: envString("GEMMA_DB_HOST", "localhost"), DBPort: envUint("GEMMA_DB_PORT", 5432), DBName: envString("GEMMA_DB_NAME", "gemma"), DBSSLMode: envString("GEMMA_DB_SSL_MODE", "require"), JWTSignKey: []byte( envString("GEMMA_JWT_SIGN_KEY", "SECRET! CHANGE ME!")), } } func envString(key, def string) string { if v, ok := os.LookupEnv(key); ok { return v } return def } func envUint(key string, def uint) uint { if v, ok := os.LookupEnv(key); ok { x, err := strconv.ParseUint(v, 10, 64) if err != nil { log.Printf("warn: invalid uint env %s: %v\n", key, err) return def } return uint(x) } return def }