http.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/web-feed/conf"
  5. "go-common/app/interface/main/web-feed/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/auth"
  9. "go-common/library/net/http/blademaster/middleware/limit/aqm"
  10. )
  11. var (
  12. feedSrv *service.Service
  13. authSvr *auth.Auth
  14. )
  15. // Init init
  16. func Init(c *conf.Config, srv *service.Service) {
  17. authSvr = auth.New(c.Auth)
  18. feedSrv = srv
  19. engine := bm.DefaultServer(c.BM)
  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. e.Ping(ping)
  28. group := e.Group("/x/web-feed", authSvr.User)
  29. {
  30. group.GET("/feed", aqm.New(nil).Limit(), feed)
  31. group.GET("/feed/unread", aqm.New(nil).Limit(), feedUnread)
  32. art := group.Group("/article")
  33. {
  34. art.GET("/feed", aqm.New(nil).Limit(), articleFeed)
  35. art.GET("/unread", aqm.New(nil).Limit(), articleFeedUnread)
  36. }
  37. }
  38. }
  39. // Ping check server ok.
  40. func ping(c *bm.Context) {
  41. if err := feedSrv.Ping(c); err != nil {
  42. log.Error("web-feed ping error(%v)", err)
  43. c.AbortWithStatus(http.StatusServiceUnavailable)
  44. }
  45. }