http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/bfs/conf"
  5. "go-common/app/admin/main/bfs/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, s *service.Service) {
  14. srv = s
  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. group := e.Group("/x/admin/bfs")
  26. {
  27. group.GET("/clusters", clusters)
  28. group.GET("/total", bfsTotal)
  29. group.GET("/rack", rackMeta)
  30. group.GET("/volume", volumeMeta)
  31. group.GET("/group", groupMeta)
  32. group.POST("/group/compact", compact)
  33. group.POST("/group/status", setGroupStatus)
  34. group.POST("/group/add_volume", addVolume)
  35. group.POST("/group/add_free_volume", addFreeVolume)
  36. }
  37. }
  38. func ping(c *bm.Context) {
  39. if err := srv.Ping(c); err != nil {
  40. log.Error("bfs ping error(%v)", err)
  41. c.Error = err
  42. c.AbortWithStatus(http.StatusServiceUnavailable)
  43. }
  44. }
  45. func register(c *bm.Context) {
  46. c.JSON(map[string]interface{}{}, nil)
  47. }