http.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/figure/conf"
  5. "go-common/app/service/main/figure/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. svc *service.Service
  12. verSvc *verify.Verify
  13. )
  14. // Init new a http server
  15. func Init(s *service.Service) {
  16. initService(s)
  17. // init router.
  18. e := bm.DefaultServer(conf.Conf.BM)
  19. internalRouter(e)
  20. if err := e.Start(); err != nil {
  21. log.Error("e.Start() error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func initService(s *service.Service) {
  26. svc = s
  27. verSvc = verify.New(conf.Conf.Verify)
  28. }
  29. // internalRouter init inner router.
  30. func internalRouter(e *bm.Engine) {
  31. e.Ping(ping)
  32. e.Register(register)
  33. group := e.Group("/x/internal/figure", verSvc.Verify)
  34. {
  35. group.GET("/info", figureInfo)
  36. group.POST("/infos", figureInfos)
  37. }
  38. }
  39. // ping check server ok.
  40. func ping(c *bm.Context) {
  41. if err := svc.Ping(c); err != nil {
  42. log.Error("figure-service service ping error (%+v)", err)
  43. c.AbortWithStatus(http.StatusServiceUnavailable)
  44. }
  45. }
  46. // register check server ok.
  47. func register(c *bm.Context) {
  48. c.JSON(map[string]interface{}{}, nil)
  49. }