client.go 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package v1
  2. import (
  3. "context"
  4. "go-common/library/log"
  5. "go-common/library/net/rpc/warden"
  6. "go-common/library/net/rpc/warden/balancer/wrr"
  7. "google.golang.org/grpc"
  8. )
  9. // AppID unique app id for service diSCovery
  10. const AppID = "ticket.service.item"
  11. //Client 客户端枚举
  12. type Client struct {
  13. IC ItemClient
  14. GC GuestClient
  15. BC BulletinClient
  16. VC VenueClient
  17. PC PlaceClient
  18. AC AreaClient
  19. SC SeatClient
  20. }
  21. // New 新建客户端实例
  22. func New(c *warden.ClientConfig) (*Client, error) {
  23. client := warden.NewClient(c, grpc.WithBalancerName(wrr.Name))
  24. conn, err := client.Dial(context.Background(), "discovery://default/"+AppID)
  25. if err != nil {
  26. log.Error("client can not connect server: %v", err)
  27. return nil, err
  28. }
  29. return &Client{
  30. IC: NewItemClient(conn),
  31. GC: NewGuestClient(conn),
  32. BC: NewBulletinClient(conn),
  33. VC: NewVenueClient(conn),
  34. PC: NewPlaceClient(conn),
  35. AC: NewAreaClient(conn),
  36. SC: NewSeatClient(conn),
  37. }, nil
  38. }