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.
42 lines
714 B
Go
42 lines
714 B
Go
2 years ago
|
package config
|
||
2 years ago
|
|
||
|
import (
|
||
|
"log"
|
||
|
"os"
|
||
|
|
||
|
"github.com/joho/godotenv"
|
||
|
)
|
||
|
|
||
2 years ago
|
var (
|
||
2 years ago
|
Mode string
|
||
|
Host string
|
||
|
BaseURL string
|
||
2 years ago
|
|
||
|
AdminPassword string
|
||
2 years ago
|
)
|
||
2 years ago
|
|
||
|
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()
|
||
|
|
||
2 years ago
|
Mode = loadEnv(os.Getenv("MODE"), "development")
|
||
|
Host = loadEnv(os.Getenv("HOST"), ":4000")
|
||
|
BaseURL = loadEnv(os.Getenv("HOST"), "http://localhost:4000")
|
||
2 years ago
|
|
||
2 years ago
|
AdminPassword = loadEnv(os.Getenv("ADMIN_PASSWORD"), "secret")
|
||
2 years ago
|
}
|