http.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/bbq/recsys/conf"
  5. "go-common/app/service/bbq/recsys/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. srv *service.Service
  12. vfy *verify.Verify
  13. )
  14. // Init init
  15. func Init(c *conf.Config, s *service.Service) {
  16. srv = s
  17. vfy = verify.New(c.Verify)
  18. engine := bm.DefaultServer(c.BM)
  19. route(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("bm Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func route(e *bm.Engine) {
  26. e.Ping(ping)
  27. e.Register(register)
  28. g := e.Group("/bbq/admin/recsys")
  29. {
  30. g.GET("/verify/start", vfy.Verify, start)
  31. g.GET("/start", start)
  32. }
  33. ga := e.Group("/bbq/admin/recsys")
  34. {
  35. ga.POST("/check/rec/message", reqRecsys)
  36. ga.POST("/check/related/message", relatedRecsys)
  37. ga.POST("/check/ups/message", upsRecsys)
  38. }
  39. }
  40. func ping(c *bm.Context) {
  41. if err := srv.Ping(c); err != nil {
  42. log.Error("ping error(%v)", err)
  43. c.AbortWithStatus(http.StatusServiceUnavailable)
  44. }
  45. }
  46. func register(c *bm.Context) {
  47. c.JSON(map[string]interface{}{}, nil)
  48. }