main_handler.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package handler
  2. import (
  3. "bet24.com/servers/micros/giftservice/handler/gift"
  4. pb "bet24.com/servers/micros/giftservice/proto"
  5. "context"
  6. "fmt"
  7. )
  8. var instance *MainService
  9. func GetInstance() *MainService {
  10. if instance == nil {
  11. instance = newHandler()
  12. }
  13. return instance
  14. }
  15. func Dump(cmd, param1, param2 string) {
  16. GetInstance().dump(cmd, param1, param2)
  17. }
  18. func newHandler() *MainService {
  19. ret := new(MainService)
  20. ret.ctor()
  21. return ret
  22. }
  23. type MainService struct{}
  24. func (h *MainService) ctor() {
  25. gift.Run()
  26. }
  27. func (d *MainService) dump(cmd, param1, param2 string) {
  28. gift.Dump(cmd, param1)
  29. }
  30. func (h *MainService) SayHello(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  31. rsp.Data = fmt.Sprintf("Hello from %s:%s", pb.ServiceName, req.Name)
  32. return nil
  33. }
  34. func (h *MainService) GetGiftList(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  35. rsp.List = gift.GetGiftList(req.UserId)
  36. return nil
  37. }
  38. func (h *MainService) GetGiftListString(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  39. rsp.Data = gift.GetGiftListString(req.UserId)
  40. return nil
  41. }
  42. func (h *MainService) GetGift(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  43. rsp.OneGift = gift.GetGift(req.GiftId, req.UserId)
  44. return nil
  45. }
  46. func (h *MainService) SendGift(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  47. rsp.IntValue, rsp.Data = gift.SendGift(req.UserId, req.ToUserId, req.GiftId)
  48. return nil
  49. }
  50. func (h *MainService) SendGiftBulk(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  51. rsp.IntValue, rsp.Data, rsp.OneGift = gift.SendGiftBulk(req.UserId, req.ToUserIds, req.GiftId, req.Num)
  52. return nil
  53. }
  54. func (h *MainService) CheckGiftCharge(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  55. rsp.BoolValue = gift.CheckGiftCharge(req.UserId, req.ProductId)
  56. return nil
  57. }
  58. func (h *MainService) GetUnclaimedGifts(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  59. rsp.UserGifts = gift.GetUnclaimedGifts(req.UserId)
  60. return nil
  61. }
  62. func (h *MainService) ClaimUserGift(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  63. rsp.Data = gift.ClaimGift(req.UserId, req.RID)
  64. return nil
  65. }
  66. func (h *MainService) CancelChargeGift(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  67. gift.CancelChargeGift(req.UserId, req.ToUserId, req.ProductId)
  68. return nil
  69. }
  70. func (h *MainService) GetReceivedGiftRecord(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
  71. rsp.Data = gift.GetReceivedGiftRecord(req.UserId)
  72. return nil
  73. }