http.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/creative/conf"
  5. "go-common/app/job/main/creative/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. //Svc service.
  11. Svc *service.Service
  12. )
  13. // Init init account service.
  14. func Init(c *conf.Config) {
  15. // service
  16. initService(c)
  17. Svc.InitCron()
  18. // init inner router
  19. eng := bm.DefaultServer(c.BM.Outer)
  20. innerRouter(eng)
  21. if err := eng.Start(); err != nil {
  22. log.Error("bm.DefaultServer error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. func initService(c *conf.Config) {
  27. Svc = service.New(c)
  28. }
  29. // innerRouter init inner router.
  30. func innerRouter(e *bm.Engine) {
  31. e.Ping(ping)
  32. e.Register(register)
  33. g := e.Group("/x/job/creative")
  34. {
  35. g.GET("/test", sendMsg)
  36. }
  37. }
  38. // ping check server ok.
  39. func ping(c *bm.Context) {
  40. if err := Svc.Ping(c); err != nil {
  41. log.Error("svr.Ping error(%v)", err)
  42. c.AbortWithStatus(http.StatusServiceUnavailable)
  43. }
  44. }
  45. func register(c *bm.Context) {
  46. c.JSON(map[string]interface{}{}, nil)
  47. }
  48. func sendMsg(c *bm.Context) {
  49. arg := new(struct {
  50. Mids []int64 `form:"mids,split" validate:"required"`
  51. })
  52. if err := c.Bind(arg); err != nil {
  53. return
  54. }
  55. c.JSON(Svc.TestSendMsg(c, arg.Mids), nil)
  56. }