-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (56 loc) · 2.4 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
package main
import (
"fmt"
"log"
"github.com/gin-gonic/gin"
"github.com/harshsinghvi/golang-fido2-passkeys-api/autoroutes"
"github.com/harshsinghvi/golang-fido2-passkeys-api/controllers"
"github.com/harshsinghvi/golang-fido2-passkeys-api/database"
"github.com/harshsinghvi/golang-fido2-passkeys-api/models"
"github.com/harshsinghvi/golang-fido2-passkeys-api/models/roles"
"github.com/harshsinghvi/golang-fido2-passkeys-api/utils"
"github.com/joho/godotenv"
)
func init() {
if err := godotenv.Load(); err != nil {
log.Printf("Error loading .env file")
}
database.ConnectDb()
gin.SetMode(gin.DebugMode)
}
func main() {
REPO_URL := utils.GetEnv("REPO_URL", "https://github.com/harshsinghvi/golang-fido2-passkeys-api")
PORT := utils.GetEnv("PORT", "8080")
router := gin.Default()
router.GET("/health", controllers.HealthHandler)
router.GET("/readiness", controllers.ReadinessHandler)
router.GET("/", controllers.ExternalRedirect(REPO_URL))
api := router.Group("/api", controllers.LoggerMW())
{
api.POST("/registration/user", controllers.NewUser)
api.GET("/login/request-challenge", controllers.RequestChallenge)
api.GET("/login/request-challenge/:passkey", controllers.RequestChallenge)
api.POST("/login/verify-challenge", controllers.VerifyChallenge)
api.POST("/register/passkey", controllers.RegistereNewPasskey)
api.GET("/verify/:id", controllers.Verificaion)
api.GET("/re-verify/u/:email", controllers.ReVerifyUser)
api.GET("/re-verify/p", controllers.ReVerifyPasskey)
api.GET("/logout", controllers.AuthMW(roles.User), controllers.Logout)
adminRouter := api.Group("/admin", controllers.ConfigMW(models.Args{"BillingDisable": true}), controllers.AuthMW(roles.SuperAdmin))
{
adminRouter.GET("/verify/passkey/:id", controllers.VerifyPasskey)
adminRouter.GET("/verify/user/:id", controllers.VerifyUser)
autoGenRouter := adminRouter.Group("/auto")
{
autoroutes.GenerateRoutes(database.DB, autoGenRouter, adminAutoRoutes)
}
}
protectedRouter := api.Group("/protected", controllers.AuthMW(roles.User))
{
protectedRouter.GET("/get-me", controllers.ConfigMW(models.Args{"BillingDisable": false}), controllers.GetMe)
protectedRouter.DELETE("/delete-user", controllers.ConfigMW(models.Args{"BillingDisable": false}), controllers.DeleteUserAndData)
autoroutes.GenerateRoutes(database.DB, protectedRouter, protectedAutoRoutes)
}
}
router.Run(fmt.Sprintf(":%s", PORT))
}