Reputation: 97
i am trying to create subroutes for my app with gorilla mux
this is my router package:
type IRouter interface {
Get(uri string, f func(w http.ResponseWriter, r *http.Request))
Post(uri string, f func(w http.ResponseWriter, r *http.Request))
Put(uri string, f func(w http.ResponseWriter, r *http.Request))
Delete(uri string, f func(w http.ResponseWriter, r *http.Request))
AddPrefix(prefix string) IRouter
Serve(port string)
}
type MuxRouter struct {
Router *mux.Router
}
func New(apiVersion string) IRouter {
constructedRouter := mux.NewRouter().PathPrefix(fmt.Sprintf("/%s/api", apiVersion)).Subrouter()
return &MuxRouter{Router: constructedRouter}
}
func (r *MuxRouter) AddPrefix(prefix string) IRouter {
subRouter := r.Router.PathPrefix(prefix).Subrouter()
return &MuxRouter{Router: subRouter}
}
func (router *MuxRouter) Get(uri string, f func(w http.ResponseWriter, r *http.Request)) {
router.Router.HandleFunc(uri, f).Methods("GET")
}
and in the main:
appRouter := router.New("v1")
router.RegisterPermissionRoutes(&appRouter, &permissionService)
and finally the function:
func RegisterPermissionRoutes(r *IRouter, s *services.IPermissionService) {
subRouter := (*r).AddPrefix("/permissions")
fmt.Println(r)
subRouter.Post("/", (*s).Create)
subRouter.Get("/", (*s).FindAll)
subRouter.Get("/{id}", (*s).FindById)
subRouter.Delete("/{id}", (*s).Delete)
subRouter.Put("/", (*s).Update)
}
but the problem is that there is no route with "permission" endpoit i don't know what am i missing
Upvotes: 0
Views: 25