|
|
|
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 UserPagesBaseUrl 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() {
|
|
|
|
godotenv.Load()
|
|
|
|
|
|
|
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
|
|
|
|
|
|
loadEnv(&Mode, "MODE", "production")
|
|
|
|
loadEnv(&Host, "HOST", "localhost:8080")
|
|
|
|
|
|
|
|
loadEnv(&GitUrl, "GIT_URL", "https://git.example.org")
|
|
|
|
loadEnv(&ChatUrl, "CHAT_URL", "https://chat.example.org")
|
|
|
|
loadEnv(&Email, "EMAIL", "mail@example.org")
|
|
|
|
|
|
|
|
loadEnv(&UserPagesBaseUrl, "USER_PAGES_BASE_URL", "https://poisson.phc.dm.unipi.it/~")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Object() util.H {
|
|
|
|
return util.H{
|
|
|
|
"Mode": Mode,
|
|
|
|
"Host": Host,
|
|
|
|
|
|
|
|
"GitUrl": GitUrl,
|
|
|
|
"ChatUrl": ChatUrl,
|
|
|
|
"Email": Email,
|
|
|
|
|
|
|
|
"UserPagesBaseUrl": UserPagesBaseUrl,
|
|
|
|
}
|
|
|
|
}
|