|
|
|
@ -14,12 +14,10 @@ import ( |
|
|
|
|
"github.com/bilibili/kratos/pkg/conf/flagvar" |
|
|
|
|
"github.com/bilibili/kratos/pkg/ecode" |
|
|
|
|
"github.com/bilibili/kratos/pkg/naming" |
|
|
|
|
"github.com/bilibili/kratos/pkg/naming/discovery" |
|
|
|
|
nmd "github.com/bilibili/kratos/pkg/net/metadata" |
|
|
|
|
"github.com/bilibili/kratos/pkg/net/netutil/breaker" |
|
|
|
|
"github.com/bilibili/kratos/pkg/net/rpc/warden/balancer/p2c" |
|
|
|
|
"github.com/bilibili/kratos/pkg/net/rpc/warden/internal/status" |
|
|
|
|
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver" |
|
|
|
|
"github.com/bilibili/kratos/pkg/net/trace" |
|
|
|
|
xtime "github.com/bilibili/kratos/pkg/time" |
|
|
|
|
|
|
|
|
@ -156,7 +154,6 @@ func NewConn(target string, opt ...grpc.DialOption) (*grpc.ClientConn, error) { |
|
|
|
|
// NewClient returns a new blank Client instance with a default client interceptor.
|
|
|
|
|
// opt can be used to add grpc dial options.
|
|
|
|
|
func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client { |
|
|
|
|
resolver.Register(discovery.Builder()) |
|
|
|
|
c := new(Client) |
|
|
|
|
if err := c.SetConfig(conf); err != nil { |
|
|
|
|
panic(err) |
|
|
|
@ -170,7 +167,6 @@ func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client { |
|
|
|
|
// DefaultClient returns a new default Client instance with a default client interceptor and default dialoption.
|
|
|
|
|
// opt can be used to add grpc dial options.
|
|
|
|
|
func DefaultClient() *Client { |
|
|
|
|
resolver.Register(discovery.Builder()) |
|
|
|
|
_once.Do(func() { |
|
|
|
|
_defaultClient = NewClient(nil) |
|
|
|
|
}) |
|
|
|
@ -226,7 +222,7 @@ func (c *Client) UseOpt(opt ...grpc.DialOption) *Client { |
|
|
|
|
|
|
|
|
|
// Dial creates a client connection to the given target.
|
|
|
|
|
// Target format is scheme://authority/endpoint?query_arg=value
|
|
|
|
|
// example: discovery://default/account.account.service?cluster=shfy01&cluster=shfy02
|
|
|
|
|
// example: direct://default/192.168.1.1:8080,192.168.1.2:8081
|
|
|
|
|
func (c *Client) Dial(ctx context.Context, target string, opt ...grpc.DialOption) (conn *grpc.ClientConn, err error) { |
|
|
|
|
if !c.conf.NonBlock { |
|
|
|
|
c.opt = append(c.opt, grpc.WithBlock()) |
|
|
|
|