@@ -13,7 +13,9 @@ import (
13
13
14
14
"github.com/krishkumar84/bdcoe-golang-portal/pkg/config"
15
15
"github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/auth"
16
+ "github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/test"
16
17
"github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/users"
18
+ "github.com/krishkumar84/bdcoe-golang-portal/pkg/middleware"
17
19
"github.com/krishkumar84/bdcoe-golang-portal/pkg/storage/mongodb"
18
20
// "github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/users"
19
21
)
@@ -33,8 +35,10 @@ func main() {
33
35
}
34
36
slog .Info ("Database connected" ,cfg .DatabaseName )
35
37
36
- //setup router
38
+ // Initialize auth middleware
39
+ authMiddleware := middleware .NewAuthMiddleware (cfg .JwtSecret )
37
40
41
+ // Setup routes
38
42
router := http .NewServeMux ()
39
43
40
44
router .HandleFunc ("GET/health" , func (w http.ResponseWriter , r * http.Request ) {
@@ -47,6 +51,20 @@ func main() {
47
51
w .Write ([]byte ("Welcome to BDCOE Portal API server is dockerized up and running" ))
48
52
})
49
53
54
+ router .Handle ("GET /api/user/test" ,
55
+ authMiddleware .Authenticate (
56
+ http .HandlerFunc (test .TestUserRoute ),
57
+ ),
58
+ )
59
+
60
+ router .Handle ("GET /api/admin/test" ,
61
+ authMiddleware .Authenticate (
62
+ authMiddleware .RequireAdmin (
63
+ http .HandlerFunc (test .TestAdminRoute ),
64
+ ),
65
+ ),
66
+ )
67
+
50
68
router .HandleFunc ("POST /api/signup" ,users .New (storage ))
51
69
router .HandleFunc ("POST /api/login" ,auth .Login (storage ,cfg .JwtSecret ))
52
70
// router.HandleFunc("GET /api/users/{id}",users.GetById(storage))
0 commit comments