http.go 912 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/activity/conf"
  5. "go-common/app/job/main/activity/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var ajSrv *service.Service
  10. // Init .
  11. func Init(conf *conf.Config, srv *service.Service) {
  12. ajSrv = srv
  13. engine := bm.DefaultServer(conf.BM)
  14. outerRouter(engine)
  15. if err := engine.Start(); err != nil {
  16. log.Error("httpx.Serve(%v) error(%+v)", conf.BM, err)
  17. panic(err)
  18. }
  19. }
  20. func outerRouter(e *bm.Engine) {
  21. e.Ping(ping)
  22. e.GET("/match/finish", finishMatch)
  23. }
  24. func ping(c *bm.Context) {
  25. if err := ajSrv.Ping(c); err != nil {
  26. log.Error("activity-job ping error")
  27. c.AbortWithStatus(http.StatusServiceUnavailable)
  28. }
  29. }
  30. func finishMatch(c *bm.Context) {
  31. v := new(struct {
  32. MoID int64 `form:"mo_id" validate:"min=1"`
  33. })
  34. if err := c.Bind(v); err != nil {
  35. return
  36. }
  37. c.JSON(nil, ajSrv.FinishMatch(c, v.MoID))
  38. }