http.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/manager/conf"
  5. "go-common/app/admin/main/manager/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. "go-common/library/net/http/blademaster/middleware/verify"
  10. "go-common/library/net/rpc/warden"
  11. )
  12. var (
  13. mngSvc *service.Service
  14. vfySvc *verify.Verify
  15. permitSvc *permit.Permit
  16. )
  17. // Init init http sever instance.
  18. func Init(c *conf.Config, s *service.Service) {
  19. mngSvc = s
  20. vfySvc = verify.New(nil)
  21. wardenConf := &warden.ClientConfig{
  22. NonBlock: true,
  23. }
  24. permitSvc = permit.New2(wardenConf)
  25. // init inner router
  26. engine := bm.DefaultServer(c.HTTPServer)
  27. innerRouter(engine)
  28. // init inner server
  29. if err := engine.Start(); err != nil {
  30. log.Error("engine.Start error(%v)", err)
  31. panic(err)
  32. }
  33. }
  34. func innerRouter(e *bm.Engine) {
  35. e.Ping(ping)
  36. g := e.Group("/x/admin/manager")
  37. {
  38. g.GET("/auth", permitSvc.Verify2(), authUser)
  39. g.GET("/heartbeat", permitSvc.Verify2(), heartbeat)
  40. g.GET("/logout", logout)
  41. g.GET("/permission", vfySvc.Verify, permissions)
  42. log := g.Group("/log", permitSvc.Permit2(""))
  43. {
  44. log.GET("/audit", searchLogAudit)
  45. log.GET("/action", searchLogAction)
  46. }
  47. internal := g.Group("/internal", vfySvc.Verify)
  48. {
  49. internal.GET("/user/role", userRole)
  50. internal.GET("/business/role", roleList)
  51. internal.GET("/tag/list", tagList)
  52. internal.GET("/control/list", tagControl)
  53. internal.GET("/user/roles", userRoles)
  54. internal.GET("/user/state/up", stateUp)
  55. internal.GET("/user/list", userList)
  56. internal.GET("/roles", allRoles)
  57. internal.POST("/role/add", addRole)
  58. }
  59. gusers := g.Group("/users", vfySvc.Verify)
  60. {
  61. gusers.GET("/department/all", departments)
  62. gusers.GET("/role/all", roles)
  63. gusers.GET("/department/relation", usersByDepartment)
  64. gusers.GET("/role/relation", usersByRole)
  65. gusers.GET("", users)
  66. gusers.GET("/total", usersTotal)
  67. gusers.GET("/unames", usersNames)
  68. gusers.GET("/uids", userIds)
  69. gusers.GET("/udepts", usersDepts)
  70. }
  71. grank := g.Group("/rank", permitSvc.Verify2())
  72. {
  73. grank.GET("/group/info", rankGroup)
  74. grank.GET("/group/list", rankGroups)
  75. grank.POST("/group/add", addRankGroup)
  76. grank.POST("/group/update", updateRankGroup)
  77. grank.POST("/group/del", delRankGroup)
  78. grank.POST("/user/add", addRankUser)
  79. grank.GET("/user/list", rankUsers)
  80. grank.POST("/user/save", saveRankUser)
  81. grank.POST("/user/del", delRankUser)
  82. }
  83. tag := g.Group("/tag", permitSvc.Permit2(""))
  84. {
  85. tag.POST("/type/add", addType)
  86. tag.POST("/type/update", updateType)
  87. tag.POST("/type/delete", deleteType)
  88. tag.POST("/add", addTag)
  89. tag.POST("/update", updateTag)
  90. tag.POST("/batch/state/update", batchUpdateState)
  91. tag.POST("/control/add", addControl)
  92. tag.POST("/control/update", updateControl)
  93. tag.POST("/attr/update", attrUpdate)
  94. tag.GET("/attr/list", attrList)
  95. tag.GET("/list", tagList)
  96. tag.GET("/type/list", typeList)
  97. tag.GET("/control", tagControl)
  98. }
  99. reason := g.Group("/reason", permitSvc.Permit2(""))
  100. {
  101. reason.GET("/catesecext/list", cateSecExtList)
  102. reason.POST("/catesecext/add", addCateSecExt)
  103. reason.POST("/catesecext/update", updateCateSecExt)
  104. reason.POST("/catesecext/ban", banCateSecExt)
  105. reason.GET("/association/list", associationList)
  106. reason.POST("/association/add", addAssociation)
  107. reason.POST("/association/update", updateAssociation)
  108. reason.POST("/association/ban", banAssociation)
  109. reason.GET("/list", reasonList)
  110. reason.POST("/add", addReason)
  111. reason.POST("/update", updateReason)
  112. reason.POST("/batch/state/update", batchUpdateReasonState)
  113. reason.GET("/dropdown/list", dropDownList)
  114. reason.GET("/business/attr", businessAttr)
  115. }
  116. business := g.Group("/business", permitSvc.Permit2(""))
  117. {
  118. business.POST("/add", addBusiness)
  119. business.POST("/update", updateBusiness)
  120. business.POST("/role/add", addRole)
  121. business.POST("/role/update", updateRole)
  122. business.POST("/user/add", addUser)
  123. business.POST("/user/update", updateUser)
  124. business.POST("/state/update", updateState)
  125. business.POST("/user/delete", deleteUser)
  126. business.GET("/list", businessList)
  127. business.GET("/flow/list", flowList)
  128. business.GET("/user/list", userList)
  129. business.GET("/role/list", roleList)
  130. business.GET("/user/role", userRole)
  131. }
  132. }
  133. }
  134. // ping check server ok.
  135. func ping(c *bm.Context) {
  136. var err error
  137. if err = mngSvc.Ping(c); err != nil {
  138. log.Error("service ping error(%v)", err)
  139. c.AbortWithStatus(http.StatusServiceUnavailable)
  140. }
  141. }