mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-06-22 01:02:29 +00:00
add client address option, fix noop resolver
This commit is contained in:
@ -36,8 +36,14 @@ func New(opts ...Option) (Client, error) {
|
||||
if !c.opts.secure {
|
||||
c.opts.dialOptions = append(c.opts.dialOptions, grpc.WithInsecure())
|
||||
}
|
||||
c.addr = fmt.Sprintf("%s:///%s", c.opts.registry.String(), c.opts.name)
|
||||
if c.opts.version != "" {
|
||||
if c.opts.addr == "" {
|
||||
c.addr = fmt.Sprintf("%s:///%s", c.opts.registry.String(), c.opts.name)
|
||||
} else if strings.HasPrefix(c.opts.addr, "tcp://"){
|
||||
c.addr = strings.Replace(c.opts.addr, "tcp://", "", 1)
|
||||
} else {
|
||||
c.addr = c.opts.addr
|
||||
}
|
||||
if c.opts.version != "" && c.opts.addr == "" {
|
||||
c.addr = c.addr + ":" + strings.TrimSpace(c.opts.version)
|
||||
}
|
||||
return c, nil
|
||||
|
@ -36,6 +36,12 @@ func WithVersion(version string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func WithAddress(address string) Option {
|
||||
return func(o *options) {
|
||||
o.addr = address
|
||||
}
|
||||
}
|
||||
|
||||
func WithTLSConfig(conf *tls.Config) Option {
|
||||
return func(o *options) {
|
||||
o.tlsConfig = conf
|
||||
@ -58,6 +64,7 @@ type options struct {
|
||||
registry registry.Registry
|
||||
name string
|
||||
version string
|
||||
addr string
|
||||
tlsConfig *tls.Config
|
||||
secure bool
|
||||
dialOptions []grpc.DialOption
|
||||
|
Reference in New Issue
Block a user