http.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/credit/conf"
  5. "go-common/app/interface/main/credit/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/antispam"
  9. "go-common/library/net/http/blademaster/middleware/auth"
  10. "go-common/library/net/http/blademaster/middleware/verify"
  11. )
  12. var (
  13. creditSvc *service.Service
  14. verifySvc *verify.Verify
  15. authSvc *auth.Auth
  16. antSvc *antispam.Antispam
  17. )
  18. // Init init http sever instance.
  19. func Init(c *conf.Config) {
  20. initService(c)
  21. engineInner := bm.DefaultServer((c.BM.Inner))
  22. // init inner router
  23. innerRouter(engineInner)
  24. if err := engineInner.Start(); err != nil {
  25. log.Error("engineInner.Start() error(%v)", err)
  26. panic(err)
  27. }
  28. }
  29. // initService init service
  30. func initService(c *conf.Config) {
  31. verifySvc = verify.New(c.Verify)
  32. authSvc = auth.New(c.AuthN)
  33. creditSvc = service.New(c)
  34. antSvc = antispam.New(c.Antispam)
  35. }
  36. // innerRouter init inner router.
  37. func innerRouter(e *bm.Engine) {
  38. // ping monitor
  39. e.Ping(ping)
  40. // internal api
  41. ig := e.Group("/x/internal/credit", verifySvc.Verify)
  42. {
  43. ig.POST("/labour/addQs", addQs)
  44. ig.POST("/labour/setQs", setQs)
  45. ig.POST("/labour/delQs", delQs)
  46. ig.GET("/labour/isanswered", isAnswered)
  47. // blocked
  48. ig.POST("/blocked/case/add", addBlockedCase)
  49. ig.POST("/blocked/info/add", addBlockedInfo)
  50. ig.POST("/blocked/info/batch/add", addBatchBlockedInfo)
  51. ig.GET("/blocked/user/num", blockedNumUser)
  52. ig.GET("/blocked/infos", batchBLKInfos)
  53. ig.GET("/blocked/cases", batchBLKCases)
  54. ig.GET("/blocked/historys", blkHistorys)
  55. // jury
  56. ig.GET("/jury/infos", batchJuryInfos)
  57. // other
  58. ig.POST("/opinion/del", delOpinion)
  59. ig.GET("/publish/infos", batchPublishs)
  60. }
  61. og := e.Group("/x/credit", bm.CORS())
  62. {
  63. // jury
  64. og.GET("/jury/requirement", authSvc.User, requirement)
  65. og.POST("/jury/apply", authSvc.User, apply)
  66. og.GET("/jury/jury", authSvc.User, jury)
  67. og.POST("/jury/caseObtain", authSvc.User, caseObtain)
  68. og.POST("/jury/vote", authSvc.User, vote)
  69. og.GET("/jury/voteInfo", authSvc.User, voteInfo)
  70. og.GET("/jury/caseInfo", authSvc.Guest, caseInfo)
  71. og.GET("/jury/juryCase", authSvc.User, juryCase)
  72. og.GET("/jury/caseList", authSvc.User, caseList)
  73. og.GET("/jury/kpi", authSvc.User, kpiList)
  74. og.GET("/jury/vote/opinion", authSvc.Guest, voteOpinion)
  75. og.GET("/jury/case/opinion", authSvc.Guest, caseOpinion)
  76. og.GET("/jury/notice", notice)
  77. og.GET("/jury/reasonList", reasonList)
  78. og.POST("/jury/caseObtain/open", authSvc.User, caseObtainByID)
  79. og.GET("/jury/juryCase/open", authSvc.Guest, spJuryCase)
  80. // appeal
  81. og.POST("/jury/appeal/add", authSvc.User, addAppeal)
  82. og.GET("/jury/appeal/status", authSvc.User, appealStatus)
  83. // labour
  84. og.GET("/labour/getQs", authSvc.User, getQs)
  85. og.POST("/labour/commitQs", authSvc.User, antSvc.Handler(), commitQs)
  86. // blocked
  87. og.GET("/blocked/user", authSvc.User, blockedUserCard)
  88. og.GET("/blocked/user/list", authSvc.User, blockedUserList)
  89. og.GET("/blocked/info", blockedInfo)
  90. og.GET("/blocked/info/appeal", authSvc.User, blockedAppeal)
  91. og.GET("/blocked/list", blockedList)
  92. // announcement
  93. og.GET("/publish/info", announcementInfo)
  94. og.GET("/publish/list", announcementList)
  95. }
  96. }
  97. // ping check server ok.
  98. func ping(c *bm.Context) {
  99. err := creditSvc.Ping(c)
  100. if err != nil {
  101. log.Error("credit interface ping error")
  102. c.AbortWithStatus(http.StatusServiceUnavailable)
  103. }
  104. }