-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (60 loc) · 1.71 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"database/sql"
"fmt"
"log"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
_ "github.com/lib/pq"
"github.com/Laurin-Notemann/tennis-analysis/api"
"github.com/Laurin-Notemann/tennis-analysis/config"
"github.com/Laurin-Notemann/tennis-analysis/db"
"github.com/Laurin-Notemann/tennis-analysis/handler"
"github.com/Laurin-Notemann/tennis-analysis/utils"
)
func main() {
ctx := context.Background()
// Parse Config
err := godotenv.Load()
if err != nil {
log.Printf("error?? loading .env file: %v\n", err)
}
var cfg config.Config
err = envconfig.Process("", &cfg)
if err != nil {
log.Fatalf("can't parse config: %v", err)
}
log.Printf("env: %v\n", cfg.DB.Url)
dbCon, err := sql.Open("postgres", cfg.DB.Url)
if err != nil {
log.Fatal(err)
}
err = dbCon.Ping()
if err != nil {
log.Fatal(err)
}
dbQueries := db.New(dbCon)
tokenGen := utils.ProdTokenGenerator{}
userHandler := handler.NewUserHandler(dbQueries, cfg)
tokenHandler := handler.NewRefreshTokenHandler(dbQueries, cfg, &tokenGen)
authHanlder := handler.NewAuthenticationHandler(dbQueries, *userHandler, *tokenHandler, &tokenGen)
playerHandler := handler.NewPlayerHandler(dbQueries)
teamHandler := handler.NewTeamHandler(dbQueries)
resourceHandler := handler.ResourceHandlers{
UserHandler: *userHandler,
TokenHandler: *tokenHandler,
AuthHandler: *authHanlder,
PlayerHandler: *playerHandler,
TeamHandler: *teamHandler,
}
server := api.NewApi(ctx, resourceHandler, &tokenGen)
echoPort := cfg.ECHO.Port
echoHost := cfg.ECHO.Host
echoString := echoHost +":"+ fmt.Sprint(echoPort)
err = server.Start(echoString)
if err != nil {
log.Fatal(err)
}
dbCon.Close()
}