http.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/workflow/conf"
  5. "go-common/app/service/main/workflow/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. verifySrv *verify.Verify
  12. wkfSvc *service.Service
  13. )
  14. // Init http server
  15. func Init(c *conf.Config, svc *service.Service) {
  16. wkfSvc = svc
  17. verifySrv = verify.New(c.Verify)
  18. engine := bm.DefaultServer(c.BM)
  19. innerRouter(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start() error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. // innerRouter
  26. func innerRouter(e *bm.Engine) {
  27. e.Ping(ping)
  28. wkfG := e.Group("/x/internal/workflow")
  29. {
  30. wkfG.POST("/add", verifySrv.Verify, addChallenge)
  31. wkfG.GET("/close", verifySrv.Verify, closeChallenge)
  32. wkfG.GET("/info", verifySrv.Verify, challengeInfo)
  33. wkfG.GET("/list", verifySrv.Verify, listChallenge)
  34. wkfG.POST("/update/state", verifySrv.Verify, upChallengeState)
  35. wkfG.GET("/extra/info", verifySrv.Verify, businessExtra)
  36. wkfG.POST("/extra/up", verifySrv.Verify, upBusinessExtra)
  37. wkfG.POST("/reply/add", verifySrv.Verify, replyAddChallenge)
  38. wkfG.GET("/untreated", verifySrv.Verify, untreatedChallenge)
  39. appealG := wkfG.Group("/appeal")
  40. {
  41. appealG.POST("/add", verifySrv.Verify, addChallenge)
  42. appealG.GET("/close", verifySrv.Verify, closeChallenge)
  43. appealG.GET("/info", verifySrv.Verify, challengeInfo)
  44. appealG.GET("/list", verifySrv.Verify, listChallenge)
  45. appealG.POST("/state", verifySrv.Verify, upChallengeState)
  46. appealG.GET("/extra/info", verifySrv.Verify, businessExtra)
  47. appealG.POST("/extra/up", verifySrv.Verify, upBusinessExtra)
  48. appealG.POST("/reply/add", verifySrv.Verify, replyAddChallenge)
  49. }
  50. appealG3 := wkfG.Group("/appeal/v3")
  51. {
  52. appealG3.POST("/add", verifySrv.Verify, addChallenge3)
  53. appealG3.GET("/list", verifySrv.Verify, listChallenge3)
  54. appealG3.GET("/state", verifySrv.Verify, groupState3)
  55. appealG3.POST("/delete", verifySrv.Verify, deleteGroup)
  56. appealG3.POST("/public/referee", verifySrv.Verify, pubRefereeGroup)
  57. }
  58. tagG3 := wkfG.Group("/tag/v3", verifySrv.Verify)
  59. {
  60. tagG3.GET("/list", tagList3)
  61. }
  62. tagG := wkfG.Group("/tag", verifySrv.Verify)
  63. {
  64. tagG.GET("/list", tagList)
  65. }
  66. sobotG := wkfG.Group("/sobot")
  67. {
  68. sobotG.GET("/user", sobotSign(sobotFetchUser))
  69. sobotG.GET("/ticket/info", verifySrv.Verify, sobotInfoTicket)
  70. sobotG.POST("/ticket/add", verifySrv.Verify, sobotAddTicket)
  71. sobotG.POST("/ticket/modify", verifySrv.Verify, sobotModifyTicket)
  72. sobotG.POST("/reply/add", verifySrv.Verify, sobotAddReply)
  73. }
  74. }
  75. }
  76. // ping check server ok.
  77. func ping(c *bm.Context) {
  78. if err := wkfSvc.Ping(c); err != nil {
  79. log.Error("workflow-service ping error(%v)", err)
  80. c.AbortWithStatus(http.StatusServiceUnavailable)
  81. }
  82. }