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.
78 lines
1.4 KiB
Go
78 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
"git.phc.dm.unipi.it/phc/website/util"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
var Mode string
|
|
var Host string
|
|
|
|
var GitUrl string
|
|
var ChatUrl string
|
|
var Email string
|
|
|
|
var BaseUrl string
|
|
|
|
var UserPagesBaseUrl string
|
|
|
|
var AuthServiceHost string
|
|
|
|
func loadEnv(target *string, name, defaultValue string) {
|
|
value := os.Getenv(name)
|
|
if len(strings.TrimSpace(value)) == 0 {
|
|
*target = defaultValue
|
|
} else {
|
|
*target = value
|
|
}
|
|
|
|
log.Printf("%s = %v", name, *target)
|
|
}
|
|
|
|
func Load() {
|
|
if err := godotenv.Load(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
|
|
// Production
|
|
loadEnv(&Mode, "MODE", "production")
|
|
loadEnv(&Host, "HOST", ":8080")
|
|
|
|
// Services
|
|
loadEnv(&GitUrl, "GIT_URL", "https://git.example.org")
|
|
loadEnv(&ChatUrl, "CHAT_URL", "https://chat.example.org")
|
|
loadEnv(&Email, "EMAIL", "mail@example.org")
|
|
|
|
// Base URL
|
|
loadEnv(&BaseUrl, "BASE_URL", "localhost:8080")
|
|
|
|
// Poisson
|
|
loadEnv(&UserPagesBaseUrl, "USER_PAGES_BASE_URL", "https://poisson.phc.dm.unipi.it/~")
|
|
|
|
// AuthService
|
|
loadEnv(&AuthServiceHost, "AUTH_SERVICE_HOST", "http://localhost:3535")
|
|
}
|
|
|
|
func Object() util.Map {
|
|
return util.Map{
|
|
"Mode": Mode,
|
|
"Host": Host,
|
|
|
|
"GitUrl": GitUrl,
|
|
"ChatUrl": ChatUrl,
|
|
"Email": Email,
|
|
|
|
"BaseUrl": BaseUrl,
|
|
|
|
"UserPagesBaseUrl": UserPagesBaseUrl,
|
|
|
|
"AuthServiceHost": AuthServiceHost,
|
|
}
|
|
}
|