From 602f8db47232bdf1b44be348bd349f1e18e10f8a Mon Sep 17 00:00:00 2001 From: Kevin Marques Date: Sat, 20 Jul 2024 11:15:28 -0300 Subject: [PATCH] :clipboard: impl: Now the main package uses the router to initialize the application's server! --- cmd/go_postr/main.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/go_postr/main.go b/cmd/go_postr/main.go index 70a7fe5..466d711 100644 --- a/cmd/go_postr/main.go +++ b/cmd/go_postr/main.go @@ -1,7 +1,29 @@ package main -import "fmt" +import ( + "os" + + "github.com/charmbracelet/log" + "github.com/joho/godotenv" + + "github.com/kevinmarquesp/go-postr/internal/router" +) + +const Dotenv = ".env" func main() { - fmt.Println("Hello world!") + if err := godotenv.Load(Dotenv); err != nil { + log.Warn("Could not load the" + Dotenv + " file. Using the system's environment from now on...") + } + + port := os.Getenv("PORT") + if port == "" { + log.Fatal("Required port variable was not found in the environment.") + } + + log.Info("Starting the application at the port " + port + ".") + + if err := router.StartRouter(port); err != nil { + log.Fatal("Router error.", "error", err) + } }