client.go 762 B

12345678910111213141516171819202122232425262728293031323334
  1. // Package v1 .
  2. // NOTE: need registery discovery resovler into grpc before use this client
  3. /*
  4. import (
  5. "go-common/library/naming/discovery"
  6. "go-common/library/net/rpc/warden/resolver"
  7. )
  8. func main() {
  9. resolver.Register(discovery.New(nil))
  10. }
  11. */
  12. package v1
  13. import (
  14. "context"
  15. "google.golang.org/grpc"
  16. "go-common/library/net/rpc/warden"
  17. )
  18. // AppID unique app id for service discovery
  19. const AppID = "passport.service.identify"
  20. // NewClient new identify grpc client
  21. func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (IdentifyClient, error) {
  22. client := warden.NewClient(cfg, opts...)
  23. conn, err := client.Dial(context.Background(), "discovery://default/"+AppID)
  24. if err != nil {
  25. return nil, err
  26. }
  27. return NewIdentifyClient(conn), nil
  28. }