foo.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package v2
  2. import (
  3. "context"
  4. v2pb "go-common/app/interface/live/live-demo/api/http/v2"
  5. "go-common/app/interface/live/live-demo/conf"
  6. "go-common/app/interface/live/live-demo/dao"
  7. "go-common/app/service/live/room/api/liverpc/v2"
  8. "go-common/library/ecode"
  9. "go-common/library/ecode/pb"
  10. "go-common/library/log"
  11. "go-common/library/net/metadata"
  12. "github.com/pkg/errors"
  13. )
  14. // FooService struct
  15. type FooService struct {
  16. conf *conf.Config
  17. // optionally add other properties here, such as dao
  18. // dao *dao.Dao
  19. }
  20. //NewFooService init
  21. func NewFooService(c *conf.Config) (s *FooService) {
  22. s = &FooService{
  23. conf: c,
  24. }
  25. return s
  26. }
  27. // Foo 相关服务
  28. // UnameByUid implementation
  29. // 根据uid得到uname
  30. // `method:"post" midware:"auth,verify"`
  31. //
  32. // 这是详细说明
  33. func (s *FooService) UnameByUid(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
  34. resp = &v2pb.Bar1Resp{}
  35. return
  36. }
  37. // GetInfo implementation
  38. // 获取房间信息
  39. func (s *FooService) GetInfo(ctx context.Context, req *v2pb.GetInfoReq) (resp *v2pb.GetInfoResp, err error) {
  40. //msg = "hello"
  41. reply, err := dao.RoomAPI.V2Room.GetByIds(ctx, &v2.RoomGetByIdsReq{Ids: []int64{int64(req.RoomId)}})
  42. if err != nil {
  43. err = errors.Wrap(&pb.Error{ErrCode: 1, ErrMessage: "call room error"}, err.Error())
  44. //msg = "Call Room Err"
  45. return
  46. }
  47. log.Info("req is %v\n", req.RoomId)
  48. room, ok := reply.Data[req.RoomId]
  49. if !ok {
  50. err = ecode.RoomNotFound
  51. return
  52. }
  53. resp = &v2pb.GetInfoResp{}
  54. resp.Roomid = room.Roomid
  55. resp.Uname = room.Uname
  56. resp.Amap = map[int32]string{123: "world"}
  57. mid, _ := metadata.Value(ctx, "mid").(int64)
  58. resp.Mid = mid
  59. //resp.LiveTime = room.LiveTime
  60. return
  61. }
  62. // UnameByUid3 implementation
  63. // 根据uid得到uname v3
  64. func (s *FooService) UnameByUid3(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
  65. resp = &v2pb.Bar1Resp{}
  66. return
  67. }
  68. // UnameByUid4 implementation
  69. // test comment
  70. func (s *FooService) UnameByUid4(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
  71. resp = &v2pb.Bar1Resp{}
  72. return
  73. }
  74. // GetDynamic implementation
  75. // `dynamic_resp:"true"`
  76. func (s *FooService) GetDynamic(ctx context.Context, req *v2pb.Bar1Req) (resp interface{}, err error) {
  77. resp = &v2pb.Bar1Resp{Uname: "hehe"}
  78. return
  79. }
  80. // Nointerface implementation
  81. // `dynamic:"true"`
  82. func (s *FooService) Nointerface(ctx context.Context, req *v2pb.Bar1Req) (resp *v2pb.Bar1Resp, err error) {
  83. resp = &v2pb.Bar1Resp{}
  84. return
  85. }
  86. // JsonReq implementation
  87. func (s *FooService) JsonReq(ctx context.Context, req *v2pb.JsonReq) (resp *v2pb.JsonResp, err error) {
  88. resp = &v2pb.JsonResp{P1: req.P1}
  89. return
  90. }