http.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/ep/saga/conf"
  5. "go-common/app/admin/ep/saga/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. )
  10. var (
  11. srv *service.Service
  12. authSvc *permit.Permit
  13. )
  14. // Init init
  15. func Init(s *service.Service) {
  16. srv = s
  17. authSvc = permit.New2(nil)
  18. engine := bm.DefaultServer(conf.Conf.BM)
  19. engine.Ping(ping)
  20. initRouter(engine)
  21. if err := engine.Start(); err != nil {
  22. log.Error("engine.Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. // initRouter init outer router api path.
  27. func initRouter(e *bm.Engine) {
  28. version := e.Group("/ep/admin/saga/v1", authSvc.Permit2(""))
  29. {
  30. project := version.Group("/projects")
  31. {
  32. project.GET("/favorite", favoriteProjects)
  33. project.POST("/favorite/edit", editFavorite)
  34. project.GET("/common", queryCommonProjects)
  35. }
  36. tasks := version.Group("/tasks")
  37. {
  38. tasks.GET("/project", projectTasks)
  39. }
  40. user := version.Group("/user")
  41. {
  42. user.GET("/query", queryUserInfo)
  43. }
  44. data := version.Group("/data")
  45. {
  46. data.GET("/teams", queryTeams)
  47. data.GET("/project", queryProjectInfo)
  48. data.GET("/project/commit", queryProjectCommit)
  49. data.GET("/project/mr", queryProjectMr)
  50. data.GET("/commit", queryCommit) // ignore
  51. data.GET("/commit/report", queryTeamCommit)
  52. data.GET("/mr/report", queryTeamMr)
  53. data.GET("/pipeline/report", queryTeamPipeline)
  54. data.GET("/project/pipelines", queryProjectPipelineLists)
  55. data.GET("/project/branch", queryProjectBranchList)
  56. data.GET("/project/members", queryProjectMembers)
  57. data.GET("/project/status", queryProjectStatus)
  58. data.GET("/project/query/types", queryProjectTypes)
  59. data.GET("/project/runners", queryProjectRunners)
  60. data.GET("/job/report", queryProjectJob)
  61. data.GET("/project/mr/report", queryProjectMrReport)
  62. data.GET("/branch/report", queryBranchDiffWith)
  63. }
  64. config := version.Group("/config")
  65. {
  66. config.GET("/whitelist", sagaUserList)
  67. //get runner sven all config files
  68. config.GET("", runnerConfig)
  69. //get saga sven all config files
  70. config.GET("/saga", sagaConfig)
  71. config.GET("/exist/saga", existConfigSaga)
  72. //public saga config
  73. config.POST("/tag/update", publicSagaConfig)
  74. //update and public saga config
  75. config.POST("/update/now/saga", releaseSagaConfig)
  76. //get current saga config
  77. config.GET("/option/saga", optionSaga)
  78. }
  79. // V1 wechat will carry cookie
  80. wechat := version.Group("/wechat")
  81. {
  82. wechat.GET("", queryContacts)
  83. contactLog := wechat.Group("/log")
  84. {
  85. contactLog.GET("/query", queryContactLogs)
  86. }
  87. redisdata := version.Group("/redisdata")
  88. {
  89. redisdata.GET("/query", queryRedisdata)
  90. }
  91. wechat.GET("/analysis/contacts", syncWechatContacts)
  92. wechat.POST("/appchat/create", createWechat)
  93. wechat.GET("/appchat/create/log", queryWechatCreateLog)
  94. wechat.GET("/appchat/get", getWechat)
  95. wechat.POST("/appchat/send", sendGroupWechat)
  96. wechat.POST("/message/send", sendWechat)
  97. wechat.POST("/appchat/update", updateWechat)
  98. }
  99. }
  100. version1 := e.Group("/ep/admin/saga/v2")
  101. {
  102. // V2 wechat will not carry cookie
  103. wechat := version1.Group("/wechat")
  104. {
  105. wechat.POST("/appchat/create", createWechat)
  106. wechat.GET("/appchat/create/log", queryWechatCreateLog)
  107. wechat.GET("/appchat/get", getWechat)
  108. wechat.POST("/appchat/send", sendGroupWechat)
  109. wechat.POST("/message/send", sendWechat)
  110. wechat.POST("/appchat/update", updateWechat)
  111. }
  112. }
  113. }
  114. func ping(c *bm.Context) {
  115. if err := srv.Ping(c); err != nil {
  116. log.Error("ping error(%v)", err)
  117. c.AbortWithStatus(http.StatusServiceUnavailable)
  118. }
  119. }