diff --git a/controller/routes.go b/controller/routes.go index 1ed0035..aa27b25 100644 --- a/controller/routes.go +++ b/controller/routes.go @@ -5,7 +5,6 @@ import ( "log" "net/http" "regexp" - "strconv" "github.com/rjNemo/go-wiki/model" ) @@ -23,8 +22,9 @@ func RegisteredRoutes() { log.Fatal(server(Port)) } -func server(p int) error { - port := ":" + strconv.Itoa(p) +func server(p string) error { + port := ":" + p + // strconv.Itoa(p) return http.ListenAndServe(port, nil) } diff --git a/controller/settings.go b/controller/settings.go index cbef706..2b9e820 100644 --- a/controller/settings.go +++ b/controller/settings.go @@ -1,4 +1,19 @@ package controller -var Port int = 8080 +import ( + "log" + "os" + + "github.com/joho/godotenv" +) + +var Port string = readEnv(".env") var tmplDir string = "templates/" + +func readEnv(f string) string { + err := godotenv.Load(".env") + if err != nil { + log.Fatal("Error loading .env file") + } + return os.Getenv("PORT") +} diff --git a/go.mod b/go.mod index b22ca79..f070856 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/rjNemo/go-wiki go 1.14 + +require github.com/joho/godotenv v1.3.0 diff --git a/main.go b/main.go index 4027b3c..484ca7b 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( ) func main() { - fmt.Printf("Start Go-wiki server on http://localhost:%d at %s\n", controller.Port, time.Now()) + + fmt.Printf("Start Go-wiki server on http://localhost:%s at %s\n", controller.Port, time.Now()) controller.RegisteredRoutes() } diff --git a/templates/base.html b/templates/base.html index d844cd5..c8866ff 100644 --- a/templates/base.html +++ b/templates/base.html @@ -13,6 +13,7 @@ integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" /> +