http.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/search/conf"
  5. "go-common/app/admin/main/search/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. authSrv *permit.Permit
  12. svr *service.Service
  13. )
  14. // Init init http
  15. func Init(c *conf.Config, s *service.Service) {
  16. svr = s
  17. authSrv = permit.New(c.Auth)
  18. engine := bm.DefaultServer(c.BM)
  19. route(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func route(e *bm.Engine) {
  26. e.Ping(ping)
  27. searchG := e.Group("/x/admin/search")
  28. {
  29. // V3新版查询和更新接口
  30. searchG.GET("/query", querySearch)
  31. searchG.GET("/query/debug", queryDebug)
  32. searchG.POST("/upsert", upsert)
  33. // V2老接口
  34. searchG.GET("/archive", archiveSearch)
  35. searchG.GET("/log", logSearch)
  36. searchG.POST("/log/delete", logDelete)
  37. searchG.GET("/log/audit", bMlogAudit)
  38. searchG.GET("/log/audit_group", bMlogAuditGroupBy)
  39. searchG.GET("/log/user_action", bMlogUserAction)
  40. // update (deprecated)
  41. searchG.POST("/archive/update", updateArchive)
  42. // index insert (deprecated)
  43. searchG.POST("/copyright/index", copyRight)
  44. // sven
  45. mng := searchG.Group("/mng")
  46. {
  47. mng.GET("/business/list", businessList)
  48. mng.GET("/business/all", businessAll)
  49. mng.GET("/business/info", businessInfo)
  50. mng.POST("/business/add", addBusiness)
  51. mng.POST("/business/update", updateBusiness)
  52. mng.POST("/business/update_app", updateBusinessApp)
  53. mng.GET("/asset/list", assetList)
  54. mng.GET("/asset/all", assetAll)
  55. mng.GET("/asset/info", assetInfo)
  56. mng.POST("/asset/add", addAsset)
  57. mng.POST("/asset/update", updateAsset)
  58. mng.GET("/app/list", appList)
  59. mng.GET("/app/info", appInfo)
  60. mng.POST("/app/add", addApp)
  61. mng.POST("/app/update", updateApp)
  62. mng.GET("/countlist", countlist)
  63. mng.GET("/count", count)
  64. mng.GET("/percent", percent)
  65. }
  66. // sven v2
  67. mng2 := searchG.Group("/mng/v2")
  68. {
  69. mng2.GET("/business/all", businessAllV2)
  70. mng2.GET("/business/info", businessInfoV2)
  71. mng2.POST("/business/add", businessAdd)
  72. mng2.POST("/business/update", businessUpdate)
  73. mng2.GET("/asset/list", assetDBTables)
  74. mng2.GET("/asset/info", assetInfoV2)
  75. mng2.GET("/asset/dbconnect", assetDBConnect)
  76. mng2.POST("/asset/dbadd", assetDBAdd)
  77. mng2.POST("/asset/tableadd", assetTableAdd)
  78. mng2.POST("/asset/tableupdate", updateAssetTable)
  79. mng2.GET("/asset/showtables", assetShowTables)
  80. mng2.GET("/asset/tablefields", assetTableFields)
  81. mng2.GET("/cluster/owners", clusterOwners)
  82. }
  83. }
  84. }
  85. // ping check health
  86. func ping(ctx *bm.Context) {
  87. if err := svr.Ping(ctx); err != nil {
  88. ctx.Error = err
  89. ctx.AbortWithStatus(http.StatusServiceUnavailable)
  90. }
  91. }