dao.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package rpc
  2. import (
  3. "context"
  4. "go-common/app/admin/main/aegis/conf"
  5. account "go-common/app/service/main/account/api"
  6. relmod "go-common/app/service/main/relation/model"
  7. relrpc "go-common/app/service/main/relation/rpc/client"
  8. uprpc "go-common/app/service/main/up/api/v1"
  9. "google.golang.org/grpc"
  10. )
  11. // Dao dao
  12. type Dao struct {
  13. c *conf.Config
  14. //gorpc
  15. relRPC RelationRPC
  16. //grpc
  17. AccountClient AccRPC
  18. UpClient UpRPC
  19. }
  20. // New init mysql db
  21. func New(c *conf.Config) (dao *Dao) {
  22. dao = &Dao{
  23. c: c,
  24. }
  25. if c.Debug != "local" {
  26. dao.relRPC = relrpc.New(c.RPC.Rel)
  27. var err error
  28. if dao.AccountClient, err = account.NewClient(c.GRPC.AccRPC); err != nil {
  29. panic(err)
  30. }
  31. if dao.UpClient, err = uprpc.NewClient(c.GRPC.UpRPC); err != nil {
  32. panic(err)
  33. }
  34. }
  35. return
  36. }
  37. // Close close the resource.
  38. func (d *Dao) Close() {
  39. }
  40. // Ping dao ping
  41. func (d *Dao) Ping(c context.Context) error {
  42. return nil
  43. }
  44. //RelationRPC .
  45. type RelationRPC interface {
  46. Stats(c context.Context, arg *relmod.ArgMids) (res map[int64]*relmod.Stat, err error)
  47. }
  48. //AccRPC .
  49. type AccRPC interface {
  50. Info3(ctx context.Context, in *account.MidReq, opts ...grpc.CallOption) (*account.InfoReply, error)
  51. Cards3(ctx context.Context, in *account.MidsReq, opts ...grpc.CallOption) (*account.CardsReply, error)
  52. ProfileWithStat3(ctx context.Context, in *account.MidReq, opts ...grpc.CallOption) (*account.ProfileStatReply, error)
  53. }
  54. //UpRPC .
  55. type UpRPC interface {
  56. UpSpecial(ctx context.Context, in *uprpc.UpSpecialReq, opts ...grpc.CallOption) (*uprpc.UpSpecialReply, error)
  57. UpsSpecial(ctx context.Context, in *uprpc.UpsSpecialReq, opts ...grpc.CallOption) (*uprpc.UpsSpecialReply, error)
  58. UpGroups(ctx context.Context, in *uprpc.NoArgReq, opts ...grpc.CallOption) (*uprpc.UpGroupsReply, error)
  59. }