http.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/cache/conf"
  5. "go-common/app/admin/main/cache/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. srv *service.Service
  11. )
  12. // Init init
  13. func Init(c *conf.Config) {
  14. srv = service.New(c)
  15. engine := bm.DefaultServer(c.BM)
  16. router(engine)
  17. if err := engine.Start(); err != nil {
  18. log.Error("engine.Start error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. func router(e *bm.Engine) {
  23. e.Ping(ping)
  24. e.Register(register)
  25. g := e.Group("/x/admin/cache")
  26. {
  27. g.GET("/clusters", clusters)
  28. g.GET("/cluster", cluster)
  29. g.GET("/cluster/detail", clusterDtl)
  30. g.POST("/cluster/add", addCluster)
  31. g.POST("/cluster/del", delCluster)
  32. g.POST("/cluster/node/modify", modifyCluster)
  33. g.GET("/cluster/toml", toml)
  34. g.POST("/cluster/from/yml", addFromYml)
  35. }
  36. ol := e.Group("/x/admin/cache/overlord")
  37. {
  38. ol.GET("/clusters", overlordClusters)
  39. ol.POST("/del/cluster", overlordDelCluster)
  40. ol.POST("/del/node", overlordDelNode)
  41. ol.GET("/ops/names", overlordOpsClusterNames)
  42. ol.GET("/ops/nodes", overlordOpsNodes)
  43. ol.POST("/import/ops/cluster", overlordImportCluster)
  44. ol.POST("/new/ops/node", overlordClusterNewNode)
  45. ol.POST("/replace/ops/node", overlordClusterReplaceNode)
  46. ol.GET("/app/clusters", overlordAppClusters)
  47. ol.GET("/app/can/bind/clusters", overlordAppNeedClusters)
  48. ol.POST("/app/cluster/bind", overlordAppClusterBind)
  49. ol.POST("/app/cluster/del", overlordAppClusterDel)
  50. ol.GET("/app/appids", overlordAppAppIDs)
  51. ol.GET("/app/toml", overlordToml)
  52. }
  53. }
  54. func ping(c *bm.Context) {
  55. if err := srv.Ping(c); err != nil {
  56. log.Error("cache-admin ping error(%v)", err)
  57. c.AbortWithStatus(http.StatusServiceUnavailable)
  58. }
  59. }
  60. func register(c *bm.Context) {
  61. c.JSON(map[string]interface{}{}, nil)
  62. }