http.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package http
  2. import (
  3. "go-common/app/service/main/search/conf"
  4. "go-common/app/service/main/search/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. var (
  9. svr *service.Service
  10. )
  11. // Init init http
  12. func Init(c *conf.Config, s *service.Service) error {
  13. svr = s
  14. // init internal router
  15. engine := bm.DefaultServer(c.HTTPServer)
  16. route(engine)
  17. // init internal server
  18. if err := engine.Start(); err != nil {
  19. log.Error("bm.Start error(%v)", err)
  20. return err
  21. }
  22. return nil
  23. }
  24. func route(e *bm.Engine) {
  25. e.Ping(ping)
  26. searchG := e.Group("/x/internal/search")
  27. {
  28. //search
  29. searchG.GET("/reply", replySearch)
  30. searchG.GET("/dmhistory", dmHistorySearch)
  31. searchG.GET("/dmhistory/test", dmHistorySearch)
  32. searchG.GET("/dm", dmSearch)
  33. searchG.GET("/dm/date", dmDate)
  34. searchG.GET("/pgc", pgcSearch)
  35. //update
  36. searchG.POST("/reply/update", replyUpdate)
  37. searchG.POST("/pgc/update", pgcUpdate)
  38. searchG.POST("/dm/update", dmUpdate)
  39. }
  40. }
  41. // ping check health
  42. func ping(ctx *bm.Context) {
  43. if err := svr.Ping(ctx); err != nil {
  44. log.Error("ping error(%v)", err)
  45. ctx.Error = err
  46. ctx.AbortWithStatus(503)
  47. }
  48. }