http.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/ep/marthe/conf"
  5. "go-common/app/admin/ep/marthe/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(c *conf.Config, s *service.Service) {
  16. srv = s
  17. authSvc = permit.New(c.Auth)
  18. engine := bm.DefaultServer(c.BM)
  19. engine.Ping(ping)
  20. outerRouter(engine)
  21. if err := engine.Start(); err != nil {
  22. log.Error("engine.Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. func outerRouter(e *bm.Engine) {
  27. base := e.Group("/ep/admin/marthe/v1", authSvc.Permit(""))
  28. {
  29. base.GET("/version", getVersion)
  30. bugly := base.Group("/bugly")
  31. {
  32. bugly.GET("/test", test)
  33. project := bugly.Group("/project") //done test
  34. {
  35. project.GET("", queryProject) //done test
  36. project.POST("/update", accessToBugly, updateProject) //done test
  37. project.POST("/query", queryProjects) //done test
  38. project.GET("/all", queryAllProjects) //done test
  39. project.GET("/versions", queryProjectVersions) // done test
  40. }
  41. version := bugly.Group("/version") //done test
  42. {
  43. version.GET("/run", accessToBugly, runVersions) //done test
  44. version.POST("/update", accessToBugly, updateVersion) //done test
  45. version.POST("/query", queryVersions) //done test
  46. version.GET("/list", getVersionAndProjectList) // done test
  47. version.POST("/batch/query", queryBatchRun)
  48. }
  49. cookie := bugly.Group("/cookie")
  50. {
  51. cookie.POST("/add", updateCookie) // done test
  52. cookie.POST("/update", updateCookie) // done test
  53. cookie.POST("/query", queryCookies) // done test
  54. cookie.GET("/status/update", updateCookieStatus) //done test
  55. }
  56. issue := bugly.Group("/issue")
  57. {
  58. issue.POST("/query", queryBuglyIssue) // done test
  59. }
  60. }
  61. tapd := base.Group("/tapd")
  62. {
  63. bug := tapd.Group("/bug")
  64. {
  65. bug.GET("/project/insert", bugInsertTapdWithProject) // done test access
  66. bug.GET("/version/insert", bugInsertTapdWithVersion) // done test access
  67. bug.POST("/filtersql/check", checkFilterSql) // done test
  68. bug.POST("/record/query", queryBugRecord) // done test
  69. bug.POST("/template/update", updateTapdBugTpl) // done test access
  70. bug.POST("/template/query", queryTapdBugTpl) // done test
  71. bug.GET("/template/all", queryAllTapdBugTpl) // done test
  72. bug.POST("/version/template/update", updateTapdBugVersionTpl) //done test access
  73. bug.POST("/version/template/query", queryTapdBugVersionTpl) //done test
  74. bug.POST("/conf/priority/update", updateTapdBugPriorityConf) //done test
  75. bug.POST("/conf/priority/query", queryTapdBugPriorityConf) //done test
  76. bug.GET("/conf/auth/check", checkAuth)
  77. }
  78. }
  79. user := base.Group("/user")
  80. {
  81. user.GET("/query", queryUserInfo) // done test
  82. user.GET("/wechat/contact/sync", syncWechatContact) // done test
  83. user.GET("/visible/bugly", updateVisibleBugly) // done test
  84. }
  85. }
  86. }
  87. func ping(c *bm.Context) {
  88. if err := srv.Ping(c); err != nil {
  89. log.Error("ping error(%v)", err)
  90. c.AbortWithStatus(http.StatusServiceUnavailable)
  91. }
  92. }
  93. func getVersion(c *bm.Context) {
  94. v := new(struct {
  95. Version string `json:"version"`
  96. })
  97. v.Version = "v.0.0.0.3"
  98. log.Info("marthe current version [%s]", v.Version)
  99. c.JSON(v, nil)
  100. }