aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorSamuel Johnson <[email protected]>2025-04-28 22:35:17 -0400
committerSamuel Johnson <[email protected]>2025-04-28 22:35:17 -0400
commit0b77727cdb52cb22ae55db5b747345c1d89a29d3 (patch)
tree385fba102ad2d8a9340834aea97b2c904372c6f5 /cmd
parent9de239a9badbbc075f1cc8079a6435f0780e5d26 (diff)
Move to using .env file
Diffstat (limited to 'cmd')
-rw-r--r--cmd/web/main.go27
1 files changed, 21 insertions, 6 deletions
diff --git a/cmd/web/main.go b/cmd/web/main.go
index 748e4bb..31137cf 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -1,19 +1,34 @@
package main
import (
- "flag"
"fmt"
"log"
"net/http"
+ "os"
+ "strconv"
+
+ "github.com/joho/godotenv"
"paterissa.net/mblog/cmd/web/handlers"
+ "paterissa.net/mblog/internal"
)
func main() {
- webmaster := flag.String("webmaster", "", "host of the website")
- port := flag.Int("port", 5050, "the hosting port")
- flag.Parse()
+ err := godotenv.Load()
+ if err != nil {
+ log.Fatal("Failed to load env")
+ }
+
+ var Env internal.Environment
+
+ Env.Webmaster = os.Getenv("webmaster")
+ Env.Db.Username = os.Getenv("db_user")
+ Env.Db.Password = os.Getenv("db_pass")
+ Env.AppPort, err = strconv.ParseUint(os.Getenv("app_port"), 10, 64)
+ if err != nil {
+ Env.AppPort = 5005
+ }
- router := handlers.RegisterEndpoints(*webmaster)
- log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), router))
+ router := handlers.RegisterEndpoints(Env.Webmaster)
+ log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", Env.AppPort), router))
}