-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (40 loc) · 1.41 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
package main
import (
"os"
"github.com/cosmos-sajal/go_boilerplate/controllers"
"github.com/cosmos-sajal/go_boilerplate/initializers"
logger "github.com/cosmos-sajal/go_boilerplate/logger"
authservice "github.com/cosmos-sajal/go_boilerplate/services/auth"
"github.com/cosmos-sajal/go_boilerplate/worker"
sentrygin "github.com/getsentry/sentry-go/gin"
"github.com/gin-gonic/gin"
)
func init() {
initializers.LoadEnvVariables()
initializers.ConnectToDB()
initializers.ConnectToRedis()
initializers.ConnectToAsyncClient()
initializers.InitialiseErrorLogger()
}
func main() {
appType := os.Getenv("APP_TYPE")
if appType == "server" {
r := gin.Default()
r.Use(logger.RequestResponseLoggerMiddleware())
r.Use(sentrygin.New(sentrygin.Options{}))
r.POST("/api/v1/user/signin/", controllers.SignInController)
r.POST("/api/v1/otp/validate/", controllers.OTPValidateController)
r.POST("/api/v1/token/refresh/", controllers.RefreshTokenController)
authGroup := r.Group("")
authGroup.Use(authservice.JWTAuthMiddleware())
authGroup.POST("/api/v1/user/", controllers.CreateUser)
authGroup.GET("/api/v1/user/", controllers.GetUserList)
authGroup.PATCH("/api/v1/user/:user_id/", controllers.UpdateUser)
r.Run() // listen and serve on 0.0.0.0:3000
} else if appType == "worker" {
worker.StartWorker(initializers.TaskServer, os.Getenv("QUEUE_NAME"))
} else {
initializers.InitialiseCron()
select {}
}
}