client.go 664 B

12345678910111213141516171819202122232425262728293031
  1. package v1
  2. import (
  3. "context"
  4. "go-common/library/net/rpc/warden"
  5. "google.golang.org/grpc"
  6. )
  7. // AppID unique app id for service discovery
  8. const AppID = "live.xlottery"
  9. // Client grpc client for interface
  10. type Client struct {
  11. CapsuleClient
  12. StormClient
  13. }
  14. // NewClient new lottery grpc client
  15. func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (*Client, error) {
  16. client := warden.NewClient(cfg, opts...)
  17. conn, err := client.Dial(context.Background(), "discovery://default/"+AppID)
  18. if err != nil {
  19. return nil, err
  20. }
  21. cli := &Client{}
  22. cli.CapsuleClient = NewCapsuleClient(conn)
  23. cli.StormClient = NewStormClient(conn)
  24. return cli, nil
  25. }