client.go 748 B

1234567891011121314151617181920212223242526272829303132333435
  1. package v1
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/net/rpc/warden"
  6. "google.golang.org/grpc"
  7. )
  8. // AppID 本服务的discoveryID
  9. const AppID = "ticket.service.sales"
  10. // TradeSalesClient .
  11. type TradeSalesClient interface {
  12. TradeClient
  13. PromotionClient
  14. }
  15. var _ TradeSalesClient = client{}
  16. type client struct {
  17. TradeClient
  18. PromotionClient
  19. }
  20. // NewClient include TradeClient adn SalesClient
  21. func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (TradeSalesClient, error) {
  22. cc, err := warden.NewClient(cfg, opts...).Dial(context.Background(), fmt.Sprintf("discovery://default/%s", AppID))
  23. if err != nil {
  24. return nil, err
  25. }
  26. return client{TradeClient: NewTradeClient(cc), PromotionClient: NewPromotionClient(cc)}, nil
  27. }