-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (40 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/dkrest1/task-manager/configs"
"github.com/dkrest1/task-manager/controllers"
"github.com/dkrest1/task-manager/routes"
_ "github.com/dkrest1/task-manager/docs"
"github.com/joho/godotenv"
"github.com/rs/cors"
)
func main() {
// Load env only if not running in Docker
if os.Getenv("DOCKER_ENV") != "true" {
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file:", err)
}
}
// init DB
configs.InitDB()
// Controllers
userController := controllers.NewUserController()
taskController := controllers.NewTaskController()
authController := controllers.NewAuthController()
// croutes
appRoutes := routes.Routes(userController, taskController, authController)
// enable cors
handler := cors.Default().Handler(appRoutes)
port := os.Getenv("PORT")
if port == "" {
log.Fatal("PORT not set in env")
}
fmt.Printf("Server is live and running on port %v 🚀🚀🚀", port)
err := http.ListenAndServe(fmt.Sprintf(":%s", port), handler)
if err != nil {
log.Fatal(err)
}
}