From 38352de02f7b851adcb3b4055616f11a5f4f3ff6 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 20 Oct 2022 11:58:21 -0500 Subject: [PATCH] Base app --- go.mod | 8 ++++++++ main.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8b15f65 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module GoWeb + +go 1.19 + +require ( + github.com/lib/pq v1.10.6 // indirect + golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect +) diff --git a/main.go b/main.go new file mode 100644 index 0000000..416586f --- /dev/null +++ b/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "GoWeb/app" + "GoWeb/config" + "GoWeb/database" + "GoWeb/routes" + "log" + "net/http" + "os" + "time" +) + +func main() { + // Create instance of App + app := app.App{} + + // Load config file to application + app.Config = config.LoadConfig() + + // Set log file + file, _ := os.Create("logs/log-" + time.Now().String() + ".log") + log.SetOutput(file) + + // Connect to database + app.Db = database.ConnectDB(&app) + + // Define Routes + routes.GetRoutes(&app) + routes.PostRoutes(&app) + + // Start server + log.Println("Starting server and listening on " + app.Config.Listen.Ip + ":" + app.Config.Listen.Port) + err := http.ListenAndServe(app.Config.Listen.Ip+":"+app.Config.Listen.Port, nil) + if err != nil { + log.Println(err) + return + } +}