You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
863 B
Go

package config
import (
"log"
"os"
"strings"
"github.com/joho/godotenv"
)
var (
Mode string
Host string
BaseURL string
// Nodes è una lista di nomi dei vari host
Nodes []string
)
func loadEnv(key string, defaultValue ...string) string {
env := os.Getenv(key)
if len(defaultValue) > 0 && env == "" {
env = defaultValue[0]
}
log.Printf("Environment variable %s = %q", key, env)
return env
}
func init() {
// Setup logger
log.SetFlags(log.Lshortfile | log.Ltime | log.Ldate)
// Load Config
godotenv.Load()
Mode = loadEnv("MODE", "development")
Host = loadEnv("HOST", ":4000")
BaseURL = loadEnv("BASE_URL", "http://localhost:4000")
nodes := loadEnv("NODES", "") // for example "node1,node2,node3"
Nodes = strings.Split(nodes, ",")
}
func IsModeDevelopment() bool {
return strings.HasPrefix(strings.ToLower(Mode), "dev")
}