http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package http
  2. import (
  3. "go-common/app/admin/main/relation/conf"
  4. "go-common/app/admin/main/relation/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/permit"
  8. )
  9. var (
  10. authSvc *permit.Permit
  11. svc *service.Service
  12. )
  13. // Init init
  14. func Init(c *conf.Config) {
  15. initService(c)
  16. // init router
  17. engine := bm.DefaultServer(c.BM)
  18. initRouter(engine)
  19. if err := engine.Start(); err != nil {
  20. log.Error("engine.Start error(%v)", err)
  21. panic(err)
  22. }
  23. }
  24. // initService init services.
  25. func initService(c *conf.Config) {
  26. authSvc = permit.New(c.Auth)
  27. svc = service.New(c)
  28. }
  29. // initRouter init outer router api path.
  30. func initRouter(e *bm.Engine) {
  31. //init api
  32. e.Ping(ping)
  33. group := e.Group("/x/admin/relation")
  34. {
  35. group.GET("/follower/followers", authSvc.Permit("RELATION_INFO"), followers)
  36. group.GET("/following/followings", authSvc.Permit("RELATION_INFO"), followings)
  37. group.GET("/logs", authSvc.Permit("RELATION_INFO"), logs)
  38. group.GET("/stat", stat)
  39. group.GET("/stats", stats)
  40. }
  41. }
  42. // ping check server ok.
  43. func ping(c *bm.Context) {
  44. svc.Ping(c)
  45. }