route.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package route
  4. import (
  5. "net/http"
  6. "github.com/gin-gonic/gin"
  7. "cp-organization-management-gateway/controller/v1"
  8. _ "cp-organization-management-gateway/docs"
  9. "cp-organization-management-gateway/route/middleware"
  10. )
  11. func SetupRoute(engine *gin.Engine) {
  12. // 404页面
  13. engine.NoRoute(func(c *gin.Context) {
  14. c.String(http.StatusNotFound, "Not Found")
  15. })
  16. // 服务健康检查
  17. engine.GET("/ping", func(c *gin.Context) {
  18. // TODO 心跳检查
  19. c.String(http.StatusOK, "pong")
  20. })
  21. //engine.Use(middleware.Session("smart-site-supplier"))
  22. // version 1
  23. apiv1 := engine.Group("/api/v1")
  24. {
  25. c := v1.NewController()
  26. engine.POST("/api/v1/user/login", c.Login)
  27. apiv1.PUT("/token_refresh", c.TokenRefresh)
  28. apiv1.Use(middleware.Jwt())
  29. system := apiv1.Group("/system")
  30. {
  31. userManagement := system.Group("/user")
  32. {
  33. userManagement.PUT("", c.UserUpdate)
  34. userManagement.POST("", c.UserCreate)
  35. userManagement.DELETE("/:id", c.UserDel)
  36. userManagement.GET("/list", c.UserList)
  37. userManagement.GET("/info/:id", c.UserInfo)
  38. }
  39. rbac := system.Group("/rbac")
  40. {
  41. node := rbac.Group("/node")
  42. {
  43. node.GET("/list", c.RbacNodeList)
  44. }
  45. group := rbac.Group("/group")
  46. {
  47. group.DELETE("/:id", c.RbacGroupDel)
  48. group.POST("", c.RbacGroupAdd)
  49. group.GET("/list", c.RbacGroupList)
  50. group.PUT("", c.RbacGroupUpdate)
  51. }
  52. }
  53. }
  54. zone := apiv1.Group("/zone")
  55. {
  56. zone.POST("", c.ZoneAdd)
  57. zone.PUT("", c.ZoneUpdate)
  58. zone.DELETE(":zone_code", c.ZoneDel)
  59. zone.GET("/list", c.ZoneList)
  60. }
  61. }
  62. }