-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (50 loc) · 1.43 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
package main
import (
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/gofiber/fiber/v2"
"github.com/joho/godotenv"
"github.com/st-matskevich/go-matchmaker/api/auth"
"github.com/st-matskevich/go-matchmaker/api/controller"
"github.com/st-matskevich/go-matchmaker/common/data"
)
func main() {
log.Println("Starting API service")
err := godotenv.Load(".env")
if err != nil {
log.Println("No .env file found")
}
redisServerURL := os.Getenv("REDIS_SERVER_URL")
clientRedis, err := data.CreateRedisDataProvider(redisServerURL)
if err != nil {
log.Fatalf("Redis connection error: %v", err)
}
log.Println("Connected to Redis")
app := fiber.New()
app.Use(
auth.New(&auth.DummyAuthorizer{}),
)
controller, err := initController(clientRedis)
if err != nil {
log.Fatalf("Failed to initialize Controller: %v", err)
}
app.Post("/request", controller.HandleCreateRequest)
log.Fatal(app.Listen(":3000"))
}
func initController(dataProvider data.DataProvider) (*controller.Controller, error) {
timeoutString := os.Getenv("RESERVATION_TIMEOUT")
reservationTimeout, err := strconv.Atoi(timeoutString)
if err != nil {
return nil, err
}
httpClient := &http.Client{Timeout: time.Duration(reservationTimeout) * time.Millisecond}
imageControlPort := os.Getenv("IMAGE_CONTROL_PORT")
return &controller.Controller{
DataProvider: dataProvider,
HttpClient: httpClient,
ImageControlPort: imageControlPort,
}, nil
}