client.go 767 B

1234567891011121314151617181920212223242526272829303132333435
  1. package v1
  2. import (
  3. "context"
  4. "google.golang.org/grpc"
  5. "go-common/library/net/rpc/warden"
  6. )
  7. const AppID = "live.resource"
  8. type Client struct {
  9. ResourceClient
  10. SplashClient
  11. BannerClient
  12. LiveCheckClient
  13. TitansClient
  14. }
  15. // NewClient new resource grpc client
  16. func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (*Client, error) {
  17. client := warden.NewClient(cfg, opts...)
  18. conn, err := client.Dial(context.Background(), "discovery://default/"+AppID)
  19. if err != nil {
  20. return nil, err
  21. }
  22. cli := &Client{}
  23. cli.ResourceClient = NewResourceClient(conn)
  24. cli.SplashClient = NewSplashClient(conn)
  25. cli.BannerClient = NewBannerClient(conn)
  26. cli.LiveCheckClient = NewLiveCheckClient(conn)
  27. cli.TitansClient = NewTitansClient(conn)
  28. return cli, nil
  29. }