Mergiate le due versioni
commit
9db584aab6
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 790 B |
@ -1,47 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Mode string
|
||||
Host string
|
||||
|
||||
GitUrl string
|
||||
ForumUrl string
|
||||
}
|
||||
|
||||
func stringOrDefault(value, defaultValue string) string {
|
||||
if len(strings.TrimSpace(value)) == 0 {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func LoadConfig() *Config {
|
||||
godotenv.Load()
|
||||
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
|
||||
Mode := stringOrDefault(os.Getenv("MODE"), "production")
|
||||
log.Printf("MODE = %v", Mode)
|
||||
|
||||
Host := stringOrDefault(os.Getenv("HOST"), "localhost:8080")
|
||||
log.Printf("HOST = %v", Host)
|
||||
|
||||
GitUrl := stringOrDefault(os.Getenv("GIT_URL"), "git.phc.dm.unipi.it")
|
||||
log.Printf("GIT_URL = %v", GitUrl)
|
||||
|
||||
ForumUrl := stringOrDefault(os.Getenv("FORUM_URL"), "forum.phc.dm.unipi.it")
|
||||
log.Printf("FORUM_URL = %v", ForumUrl)
|
||||
|
||||
return &Config{
|
||||
Mode, Host, GitUrl, ForumUrl,
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var Mode string
|
||||
var Host string
|
||||
|
||||
var GitUrl string
|
||||
var ForumUrl string
|
||||
|
||||
func stringOrDefault(value, defaultValue string) string {
|
||||
if len(strings.TrimSpace(value)) == 0 {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func LoadConfig() {
|
||||
godotenv.Load()
|
||||
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
|
||||
Mode = stringOrDefault(os.Getenv("MODE"), "production")
|
||||
log.Printf("MODE = %v", Mode)
|
||||
|
||||
Host = stringOrDefault(os.Getenv("HOST"), "localhost:8080")
|
||||
log.Printf("HOST = %v", Host)
|
||||
|
||||
GitUrl = stringOrDefault(os.Getenv("GIT_URL"), "git.phc.dm.unipi.it")
|
||||
log.Printf("GIT_URL = %v", GitUrl)
|
||||
|
||||
ForumUrl = stringOrDefault(os.Getenv("FORUM_URL"), "forum.phc.dm.unipi.it")
|
||||
log.Printf("FORUM_URL = %v", ForumUrl)
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
module git.phc.dm.xxxxx.xx/server-poisson
|
||||
module github.com/phc-dm/server-poisson
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/go-chi/chi/v5 v5.0.7 // indirect
|
||||
github.com/joho/godotenv v1.4.0 // indirect
|
||||
github.com/labstack/echo/v4 v4.1.16
|
||||
github.com/go-chi/chi/v5 v5.0.7
|
||||
github.com/joho/godotenv v1.4.0
|
||||
)
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
After Width: | Height: | Size: 133 KiB |
Loading…
Reference in New Issue