-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (37 loc) · 1.02 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
package main
import (
"github.com/jesper-nord/recurringly-backend/auth"
"github.com/jesper-nord/recurringly-backend/postgres"
"github.com/jesper-nord/recurringly-backend/router"
"github.com/jesper-nord/recurringly-backend/task"
"github.com/joho/godotenv"
"log"
"net/http"
"os"
)
func main() {
_ = godotenv.Load()
db, err := postgres.Initialize()
if err != nil {
log.Panicf("failed to connect to database: %v", err)
}
taskRepository := task.NewRepository(db)
err = taskRepository.Migrate()
if err != nil {
log.Panicf("failed to migrate schemas: %v", err)
}
authRepository := auth.NewRepository(db)
err = authRepository.Migrate()
if err != nil {
log.Panicf("failed to migrate schemas: %v", err)
}
routes := router.New(task.NewService(taskRepository), auth.NewService(authRepository))
port := getEnvWithFallback("PORT", "8090")
log.Fatal(http.ListenAndServe(":"+port, routes))
}
func getEnvWithFallback(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}