grpc.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package dao
  2. import (
  3. "context"
  4. broadcasrtService "go-common/app/service/live/broadcast-proxy/api/v1"
  5. "go-common/app/service/live/live-dm/conf"
  6. xuserService "go-common/app/service/live/xuser/api/grpc/v1"
  7. acctountService "go-common/app/service/main/account/api"
  8. filterService "go-common/app/service/main/filter/api/grpc/v1"
  9. locationService "go-common/app/service/main/location/api"
  10. spyService "go-common/app/service/main/spy/api"
  11. "go-common/library/net/rpc/warden"
  12. "google.golang.org/grpc"
  13. )
  14. //LocationAppID location服务注册ID
  15. const locationAppID = "location.service"
  16. const vipAppID = "live.xuser"
  17. var (
  18. ac acctountService.AccountClient
  19. vipCli xuserService.VipClient
  20. //FilterClient 屏蔽词过滤
  21. FilterClient filterService.FilterClient
  22. //LcClient 地理区域信息
  23. LcClient locationService.LocationClient
  24. //SpyClient 用户真实分
  25. SpyClient spyService.SpyClient
  26. //BcastClient 弹幕推送
  27. BcastClient *broadcasrtService.Client
  28. //UserExp 用户等级
  29. userExp *xuserService.Client
  30. //isAdmin 房管
  31. isAdmin xuserService.RoomAdminClient
  32. )
  33. //InitGrpc 初始化grpcclient
  34. func InitGrpc(c *conf.Config) {
  35. var err error
  36. ac, err = acctountService.NewClient(c.AccClient)
  37. if err != nil {
  38. panic(err)
  39. }
  40. FilterClient, err = filterService.NewClient(c.FilterClient)
  41. if err != nil {
  42. panic(err)
  43. }
  44. LcClient, err = newLocationClient(c.LocationClient)
  45. if err != nil {
  46. panic(err)
  47. }
  48. vipCli, err = newVipService(c.XuserClent)
  49. if err != nil {
  50. panic(err)
  51. }
  52. SpyClient, err = spyService.NewClient(c.SpyClient)
  53. if err != nil {
  54. panic(err)
  55. }
  56. BcastClient, err = broadcasrtService.NewClient(c.BcastClient)
  57. if err != nil {
  58. panic(err)
  59. }
  60. userExp, err = xuserService.NewClient(c.UExpClient)
  61. if err != nil {
  62. panic(err)
  63. }
  64. isAdmin, err = xuserService.NewXuserRoomAdminClient(c.IsAdminClient)
  65. if err != nil {
  66. panic(err)
  67. }
  68. }
  69. //创建Location服务client
  70. func newLocationClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (locationService.LocationClient, error) {
  71. client := warden.NewClient(cfg, opts...)
  72. conn, err := client.Dial(context.Background(), "discovery://default/"+locationAppID)
  73. if err != nil {
  74. return nil, err
  75. }
  76. return locationService.NewLocationClient(conn), nil
  77. }
  78. func newVipService(cfg *warden.ClientConfig, opts ...grpc.DialOption) (xuserService.VipClient, error) {
  79. client := warden.NewClient(cfg, opts...)
  80. conn, err := client.Dial(context.Background(), "discovery://default/"+vipAppID)
  81. if err != nil {
  82. return nil, err
  83. }
  84. return xuserService.NewVipClient(conn), nil
  85. }