http.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package http
  2. import (
  3. "go-common/app/admin/main/workflow/service"
  4. "go-common/library/conf/paladin"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/permit"
  8. )
  9. var (
  10. authSvc *permit.Permit
  11. wkfSvc *service.Service
  12. )
  13. // Init http server
  14. func Init(s *service.Service) {
  15. var (
  16. hc struct {
  17. BM *bm.ServerConfig
  18. Permit *permit.Config
  19. }
  20. )
  21. if err := paladin.Get("http.toml").UnmarshalTOML(&hc); err != nil {
  22. panic(err)
  23. }
  24. // init service
  25. iniService(hc.Permit, s)
  26. // init internal router
  27. engine := bm.DefaultServer(hc.BM)
  28. //global timeout
  29. setupInnerEngine(engine)
  30. // init internal server
  31. if err := engine.Start(); err != nil {
  32. log.Error("engine.Start error(%v)", err)
  33. panic(err)
  34. }
  35. }
  36. func iniService(auth *permit.Config, s *service.Service) {
  37. authSvc = permit.New(auth)
  38. wkfSvc = s
  39. }
  40. // innerRouter
  41. func setupInnerEngine(e *bm.Engine) {
  42. // monitor ping
  43. e.Ping(ping)
  44. workflow := e.Group("/x/admin/workflow")
  45. // platform
  46. platform := workflow.Group("/platform", authSvc.Permit(""))
  47. {
  48. platform.GET("/count", platformChallCount)
  49. platform.GET("/list/pending", platformChallListPending)
  50. platform.GET("/list/handling", platformHandlingChalllist)
  51. platform.GET("/list/done", platformDoneChallList)
  52. platform.GET("/list/created", platformCreatedChallList)
  53. platform.GET("/release", platformRelease)
  54. platform.GET("/checkin", platformCheckIn)
  55. }
  56. // challenge
  57. challenge := workflow.Group("/challenge")
  58. {
  59. challenge.GET("/list", challList)
  60. challenge.GET("/list2", authSvc.Permit(""), challListCommon)
  61. challenge.GET("/detail", challDetail)
  62. challenge.GET("/activity/list", listChallActivity)
  63. challenge.GET("/business/list", listChallBusiness) // Deprecated
  64. challenge.POST("/update", authSvc.Permit(""), upChall)
  65. challenge.POST("/reset", authSvc.Permit(""), rstChallResult)
  66. challenge.POST("/state/set", authSvc.Permit(""), setChallResult) // new api logic
  67. challenge.POST("/state/batch/set", authSvc.Permit(""), batchSetChallResult) //new api logic
  68. challenge.POST("/batch/result/set", authSvc.Permit(""), batchSetChallResult) // todo: deprecated
  69. challenge.POST("/extra/update", authSvc.Permit(""), upChallExtra)
  70. challenge.POST("/extra/batch/update", authSvc.Permit(""), batchUpChallExtra)
  71. challenge.POST("/business/state/set", authSvc.Permit(""), upChallBusState)
  72. challenge.POST("/business/state/batch/set", authSvc.Permit(""), batchUpChallBusState)
  73. // manager-v4 used
  74. challenge.POST("/business/busState/update", upBusChallsBusState) //Deprecated
  75. challenge.POST("/reset/business/state/batch/set", upBusChallsBusState)
  76. // challenge event
  77. event := challenge.Group("/event")
  78. event.POST("/add", addEvent)
  79. event.POST("/batch/add", batchAddEvent)
  80. event.GET("/list", eventList)
  81. // call reply/add sync add event and set business_state
  82. reply := challenge.Group("/reply")
  83. reply.POST("/add", authSvc.Permit(""), addReply)
  84. reply.POST("/batch/add", authSvc.Permit(""), batchAddReply)
  85. }
  86. // business
  87. business := workflow.Group("/business")
  88. {
  89. business.GET("/meta/list", busMetaList)
  90. // callback
  91. callback := business.Group("/callback")
  92. {
  93. callback.GET("/list", listCallback)
  94. callback.POST("/add", authSvc.Permit(""), addOrUpCallback)
  95. callback.POST("/external/api/set", setExtAPI)
  96. }
  97. // attr
  98. busAttr := business.Group("/attr")
  99. {
  100. busAttr.GET("/list", listBusAttr)
  101. busAttr.POST("/add", addOrUpdateBusAttr)
  102. }
  103. }
  104. // todo: workflow_v3
  105. v3 := workflow.Group("/v3")
  106. challenge3 := v3.Group("/challenge", authSvc.Permit(""))
  107. {
  108. challenge3.GET("/list", challListV3)
  109. challenge3.POST("/update", upChallV3)
  110. challenge3.POST("/reset", rstChallResultV3)
  111. challenge3.POST("/state/set", setChallStateV3)
  112. challenge3.POST("/business/state/set", upChallBusStateV3)
  113. challenge3.POST("/extra/update", upChallExtraV3)
  114. }
  115. group3 := v3.Group("/group", authSvc.Permit(""))
  116. {
  117. group3.GET("/list", groupListV3)
  118. group3.GET("/pending/count", countPendingGroup)
  119. group3.POST("/role/set", setGroupRole) //角色流转
  120. group3.POST("/state/set", setGroupStateV3) //工单状态变更/处罚
  121. group3.POST("/extra/update", upGroupExtra)
  122. group3.POST("/public/referee/set", setPublicReferee) //移交众裁
  123. }
  124. bus3 := v3.Group("/business")
  125. {
  126. attr3 := bus3.Group("/attr")
  127. {
  128. attr3.GET("/list", listBusAttrV3)
  129. attr3.POST("/button/switch", setSwitch)
  130. attr3.POST("/button/shortcut/set", setShortCut)
  131. }
  132. mng := bus3.Group("/manager")
  133. {
  134. mng.GET("/tag", mngTag)
  135. }
  136. source := bus3.Group("/source")
  137. {
  138. source.GET("/list", srcList)
  139. }
  140. }
  141. v3.GET("/user/block/info", userBlockInfo) //单个用户封禁次数/封禁状态
  142. }
  143. // ping check server ok.
  144. func ping(ctx *bm.Context) {
  145. if err := wkfSvc.Ping(ctx); err != nil {
  146. ctx.Error = err
  147. ctx.AbortWithStatus(503)
  148. }
  149. }