-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (57 loc) · 1.64 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
package main
import (
"context"
"log"
"os"
"os/signal"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/santichoks/stc-auth-service/config"
"github.com/santichoks/stc-auth-service/controllers"
"github.com/santichoks/stc-auth-service/middleware"
"github.com/santichoks/stc-auth-service/pkgs/databasePkg"
"github.com/santichoks/stc-auth-service/repositories"
"github.com/santichoks/stc-auth-service/router"
"github.com/santichoks/stc-auth-service/services"
)
func main() {
// Initial Configs
cfg := config.GetConfig()
// MongoDB and Redis Connection
mongo := databasePkg.NewMongoConnection(&cfg)
redis := databasePkg.NewRedisConnection(&cfg)
defer mongo.Disconnect(context.Background())
defer redis.Close()
authMongoRepo := repositories.NewAuthMongoRepository(mongo)
authRedisRepo := repositories.NewAuthRedisRepository(redis)
authSrv := services.NewAuthService(authMongoRepo, authRedisRepo)
authCtrl := controllers.NewAuthController(authSrv, &cfg)
authMdw := middleware.NewGatewayMiddleware(authRedisRepo, &cfg)
// Initial Fiber Server
app := fiber.New()
// Initial CORS request
app.Use(cors.New(cors.Config{
AllowOrigins: cfg.AllowOrigins,
AllowMethods: strings.Join([]string{
fiber.MethodGet,
fiber.MethodPost,
fiber.MethodPut,
fiber.MethodPatch,
fiber.MethodDelete,
}, ","),
AllowCredentials: true,
}))
// Initial Routes
router.AuthRoute(app, authMdw, authCtrl)
// Graceful Shutdown
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
go func() {
<-quit
app.Shutdown()
}()
if err := app.Listen(":8080"); err != nil {
log.Fatal(err)
}
}