dao.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/live/app-ucenter/conf"
  5. fans_medal_api "go-common/app/service/live/fans_medal/api/liverpc"
  6. relation_api "go-common/app/service/live/relation/api/liverpc"
  7. resource_cli "go-common/app/service/live/resource/api/grpc/v1"
  8. room_api "go-common/app/service/live/room/api/liverpc"
  9. user_api "go-common/app/service/live/user/api/liverpc"
  10. member_cli "go-common/app/service/main/member/api"
  11. bm "go-common/library/net/http/blademaster"
  12. "go-common/library/net/rpc/liverpc"
  13. )
  14. // Dao dao
  15. type Dao struct {
  16. c *conf.Config
  17. RoomApi *room_api.Client
  18. UserApi *user_api.Client
  19. RelationApi *relation_api.Client
  20. FansMedalApi *fans_medal_api.Client
  21. memberCli member_cli.MemberClient
  22. titansCli resource_cli.TitansClient
  23. HttpCli *bm.Client
  24. }
  25. // New init mysql db
  26. func New(c *conf.Config) (dao *Dao) {
  27. dao = &Dao{
  28. c: c,
  29. RoomApi: room_api.New(getConf("room")),
  30. UserApi: user_api.New(getConf("user")),
  31. RelationApi: relation_api.New(getConf("relation")),
  32. FansMedalApi: fans_medal_api.New(getConf("fans_medal")),
  33. HttpCli: bm.NewClient(c.HttpClient),
  34. }
  35. MemberCli, err := member_cli.NewClient(c.GrpcCli)
  36. if err != nil {
  37. panic(err)
  38. }
  39. dao.memberCli = MemberCli
  40. TitansCli, errTitans := resource_cli.NewClient(c.GrpcCli)
  41. if errTitans != nil {
  42. panic(err)
  43. }
  44. dao.titansCli = TitansCli
  45. return
  46. }
  47. // Close close the resource.
  48. func (d *Dao) Close() {
  49. }
  50. // Ping dao ping
  51. func (d *Dao) Ping(c context.Context) error {
  52. // TODO: if you need use mc,redis, please add
  53. return nil
  54. }
  55. func getConf(appName string) *liverpc.ClientConfig {
  56. c := conf.Conf.LiveRpc
  57. if c != nil {
  58. return c[appName]
  59. }
  60. return nil
  61. }