From deaccf048df299323f352756ac3bc04a2c429930 Mon Sep 17 00:00:00 2001 From: wangjian Date: Fri, 6 Jan 2023 17:48:53 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/router/router.go | 154 +++++++++++++++++++++++----------------------- 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/internal/router/router.go b/internal/router/router.go index 6a1e25a..d5ab3cd 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -14,95 +14,97 @@ import ( func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine { hs := handler.NewHandlerService(engine, logger) gin.SetMode(gin.ReleaseMode) - r := gin.New() - r.Use(ginzap.Ginzap(logger, "2006-01-02 15:04:05.000", true)) - r.Use(middleware.Cors()) - - user := r.Group("/user") + root := gin.New() + root.Use(ginzap.Ginzap(logger, "2006-01-02 15:04:05.000", true)) + root.Use(middleware.Cors()) + r := root.Group("/api") { - user.Use(middleware.JwtAuthMiddleware(logger)) - user.POST("/login", e.ErrorWrapper(hs.Login)) - user.GET("/getUserInfo", e.ErrorWrapper(hs.GetUserInfo)) - } - manage := r.Group("/manage") - { - manage.Use(middleware.JwtAuthMiddleware(logger)) - owner := manage.Group("/owner") + user := r.Group("/user") { - owner.POST("/list", e.ErrorWrapper(hs.OwnerList)) - owner.POST("/add", e.ErrorWrapper(hs.AddOwner)) - owner.POST("/edit", e.ErrorWrapper(hs.EditOwner)) - owner.POST("/delete", e.ErrorWrapper(hs.DelOwner)) + user.Use(middleware.JwtAuthMiddleware(logger)) + user.POST("/login", e.ErrorWrapper(hs.Login)) + user.GET("/getUserInfo", e.ErrorWrapper(hs.GetUserInfo)) } - project := manage.Group("/project") + manage := r.Group("/manage") { - project.POST("/list", e.ErrorWrapper(hs.ProjectList)) - project.POST("/add", e.ErrorWrapper(hs.AddProject)) - project.POST("/edit", e.ErrorWrapper(hs.EditProject)) - project.POST("/delete", e.ErrorWrapper(hs.DelProject)) - - } - product := manage.Group("/product") - { - product.POST("/list", e.ErrorWrapper(hs.ProductList)) - product.POST("/add", e.ErrorWrapper(hs.AddProduct)) - product.POST("/edit", e.ErrorWrapper(hs.EditProduct)) - product.POST("/delete", e.ErrorWrapper(hs.DelProduct)) - - category := product.Group("/category") + manage.Use(middleware.JwtAuthMiddleware(logger)) + owner := manage.Group("/owner") { - category.POST("/list", e.ErrorWrapper(hs.CategoryList)) - category.POST("/add", e.ErrorWrapper(hs.AddCategory)) - category.POST("/edit", e.ErrorWrapper(hs.EditCategory)) - category.POST("/delete", e.ErrorWrapper(hs.DelCategory)) + owner.POST("/list", e.ErrorWrapper(hs.OwnerList)) + owner.POST("/add", e.ErrorWrapper(hs.AddOwner)) + owner.POST("/edit", e.ErrorWrapper(hs.EditOwner)) + owner.POST("/delete", e.ErrorWrapper(hs.DelOwner)) } - attribute := product.Group("/attribute") + project := manage.Group("/project") { - attribute.POST("/list", e.ErrorWrapper(hs.AttributeList)) - attribute.POST("/add", e.ErrorWrapper(hs.AddAttribute)) - attribute.POST("/edit", e.ErrorWrapper(hs.EditAttribute)) - attribute.POST("/delete", e.ErrorWrapper(hs.DelAttribute)) - } - event := product.Group("/event") - { - event.POST("/list", e.ErrorWrapper(hs.EventList)) - event.POST("/add", e.ErrorWrapper(hs.AddEvent)) - event.POST("/edit", e.ErrorWrapper(hs.EditEvent)) - event.POST("/delete", e.ErrorWrapper(hs.DelEvent)) + project.POST("/list", e.ErrorWrapper(hs.ProjectList)) + project.POST("/add", e.ErrorWrapper(hs.AddProject)) + project.POST("/edit", e.ErrorWrapper(hs.EditProject)) + project.POST("/delete", e.ErrorWrapper(hs.DelProject)) - params := event.Group("/params") + } + product := manage.Group("/product") + { + product.POST("/list", e.ErrorWrapper(hs.ProductList)) + product.POST("/add", e.ErrorWrapper(hs.AddProduct)) + product.POST("/edit", e.ErrorWrapper(hs.EditProduct)) + product.POST("/delete", e.ErrorWrapper(hs.DelProduct)) + + category := product.Group("/category") { - params.POST("/list", e.ErrorWrapper(hs.EventParamsList)) - params.POST("/add", e.ErrorWrapper(hs.AddEventParams)) - params.POST("/edit", e.ErrorWrapper(hs.EditEventParams)) - params.POST("/delete", e.ErrorWrapper(hs.DelEventParams)) + category.POST("/list", e.ErrorWrapper(hs.CategoryList)) + category.POST("/add", e.ErrorWrapper(hs.AddCategory)) + category.POST("/edit", e.ErrorWrapper(hs.EditCategory)) + category.POST("/delete", e.ErrorWrapper(hs.DelCategory)) } - - } - service := product.Group("/service") - { - service.POST("/list", e.ErrorWrapper(hs.ServiceList)) - service.POST("/add", e.ErrorWrapper(hs.AddService)) - service.POST("/edit", e.ErrorWrapper(hs.EditService)) - service.POST("/delete", e.ErrorWrapper(hs.DelService)) - - params := service.Group("/params") + attribute := product.Group("/attribute") { - params.POST("/list", e.ErrorWrapper(hs.ServiceParamsList)) - params.POST("/add", e.ErrorWrapper(hs.AddServiceParams)) - params.POST("/edit", e.ErrorWrapper(hs.EditServiceParams)) - params.POST("/delete", e.ErrorWrapper(hs.DelServiceParams)) + attribute.POST("/list", e.ErrorWrapper(hs.AttributeList)) + attribute.POST("/add", e.ErrorWrapper(hs.AddAttribute)) + attribute.POST("/edit", e.ErrorWrapper(hs.EditAttribute)) + attribute.POST("/delete", e.ErrorWrapper(hs.DelAttribute)) + } + event := product.Group("/event") + { + event.POST("/list", e.ErrorWrapper(hs.EventList)) + event.POST("/add", e.ErrorWrapper(hs.AddEvent)) + event.POST("/edit", e.ErrorWrapper(hs.EditEvent)) + event.POST("/delete", e.ErrorWrapper(hs.DelEvent)) + + params := event.Group("/params") + { + params.POST("/list", e.ErrorWrapper(hs.EventParamsList)) + params.POST("/add", e.ErrorWrapper(hs.AddEventParams)) + params.POST("/edit", e.ErrorWrapper(hs.EditEventParams)) + params.POST("/delete", e.ErrorWrapper(hs.DelEventParams)) + } + + } + service := product.Group("/service") + { + service.POST("/list", e.ErrorWrapper(hs.ServiceList)) + service.POST("/add", e.ErrorWrapper(hs.AddService)) + service.POST("/edit", e.ErrorWrapper(hs.EditService)) + service.POST("/delete", e.ErrorWrapper(hs.DelService)) + + params := service.Group("/params") + { + params.POST("/list", e.ErrorWrapper(hs.ServiceParamsList)) + params.POST("/add", e.ErrorWrapper(hs.AddServiceParams)) + params.POST("/edit", e.ErrorWrapper(hs.EditServiceParams)) + params.POST("/delete", e.ErrorWrapper(hs.DelServiceParams)) + } } } } + model := r.Group("/model") + { + model.Use(middleware.JwtAuthMiddleware(logger)) + model.POST("/list", e.ErrorWrapper(hs.ModelList)) + model.POST("/add", e.ErrorWrapper(hs.AddModel)) + model.POST("/edit", e.ErrorWrapper(hs.EditModel)) + model.POST("/delete", e.ErrorWrapper(hs.DelModel)) + } } - model := r.Group("/model") - { - model.Use(middleware.JwtAuthMiddleware(logger)) - model.POST("/list", e.ErrorWrapper(hs.ModelList)) - model.POST("/add", e.ErrorWrapper(hs.AddModel)) - model.POST("/edit", e.ErrorWrapper(hs.EditModel)) - model.POST("/delete", e.ErrorWrapper(hs.DelModel)) - } - return r + return root }