@@ -13,7 +13,9 @@ import (
1313
1414 "github.com/krishkumar84/bdcoe-golang-portal/pkg/config"
1515 "github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/auth"
16+ "github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/test"
1617 "github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/users"
18+ "github.com/krishkumar84/bdcoe-golang-portal/pkg/middleware"
1719 "github.com/krishkumar84/bdcoe-golang-portal/pkg/storage/mongodb"
1820 // "github.com/krishkumar84/bdcoe-golang-portal/pkg/http/handler/users"
1921)
@@ -33,8 +35,10 @@ func main() {
3335 }
3436 slog .Info ("Database connected" ,cfg .DatabaseName )
3537
36- //setup router
38+ // Initialize auth middleware
39+ authMiddleware := middleware .NewAuthMiddleware (cfg .JwtSecret )
3740
41+ // Setup routes
3842 router := http .NewServeMux ()
3943
4044 router .HandleFunc ("GET/health" , func (w http.ResponseWriter , r * http.Request ) {
@@ -47,6 +51,20 @@ func main() {
4751 w .Write ([]byte ("Welcome to BDCOE Portal API server is dockerized up and running" ))
4852 })
4953
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+
5068 router .HandleFunc ("POST /api/signup" ,users .New (storage ))
5169 router .HandleFunc ("POST /api/login" ,auth .Login (storage ,cfg .JwtSecret ))
5270 // router.HandleFunc("GET /api/users/{id}",users.GetById(storage))
0 commit comments