http.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/coupon/conf"
  5. "go-common/app/service/main/coupon/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. verifySvc *verify.Verify
  12. svc *service.Service
  13. )
  14. // Init init
  15. func Init(c *conf.Config, s *service.Service) {
  16. svc = s
  17. initService(c)
  18. engine := bm.DefaultServer(c.BM)
  19. interRouter(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. // initService init services.
  26. func initService(c *conf.Config) {
  27. verifySvc = verify.New(nil)
  28. }
  29. // interRouter init inner router api path.
  30. func interRouter(e *bm.Engine) {
  31. //init api
  32. e.Ping(ping)
  33. e.Register(register)
  34. group := e.Group("/x/internal/coupon", verifySvc.Verify)
  35. {
  36. group.GET("/count", userCoupon)
  37. group.POST("/use", useCoupon)
  38. group.GET("/info", couponInfo)
  39. group.POST("/add", addCoupon)
  40. group.POST("/change", changeCoupon)
  41. group.POST("/cartoon/use", useCartoonCoupon)
  42. group.POST("/grant", salaryCoupon)
  43. ae := group.Group("/allowance")
  44. ae.POST("/use", useAllowance)
  45. ae.POST("/notify", useNotify)
  46. ae.GET("/count", allowanceCount)
  47. ae.POST("/receive", receiveAllowance)
  48. // 元旦活动
  49. group.GET("/prize/cards", prizeCards)
  50. group.POST("/prize/draw", prizeDraw)
  51. }
  52. }
  53. // ping check server ok.
  54. func ping(c *bm.Context) {
  55. if err := svc.Ping(c); err != nil {
  56. log.Error("coupon http service ping error(%v)", err)
  57. c.AbortWithStatus(http.StatusServiceUnavailable)
  58. }
  59. }
  60. // register check server ok.
  61. func register(c *bm.Context) {
  62. c.JSON(map[string]interface{}{}, nil)
  63. }