Skip to content

Commit

Permalink
Update code to use new target.URL field (all other fields are depreca…
Browse files Browse the repository at this point in the history
…ted)

Signed-off-by: Andrew Mason <andrew@planetscale.com>
  • Loading branch information
Andrew Mason committed Apr 4, 2022
1 parent 6efd9d8 commit 3d7ab09
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions go/vt/vtadmin/cluster/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ type Options struct {
// the scheme should be a cluster ID.
//
// The target provided to Builder.Build will be used to switch on vtctld or
// vtgate, based on the Authority field of the target. This means that the addr
// passed to Dial should have the form "{clusterID}://{vtctld|vtgate}/". Other
// target Authorities will cause an error.
// vtgate, based on the URL.Host field of the parsed dial target. This means
// that the addr passed to Dial should have the form
// "{clusterID}://{vtctld|vtgate}/". Other target URL hosts will cause an error.
// To ensure the dial address conforms to this constraint, use this package's
// DialAddr function.
func (opts *Options) NewBuilder(scheme string) grpcresolver.Builder {
return &builder{
scheme: scheme,
Expand Down Expand Up @@ -175,13 +177,13 @@ func (b *builder) Build(target grpcresolver.Target, cc grpcresolver.ClientConn,

func (b *builder) build(target grpcresolver.Target, cc grpcresolver.ClientConn, opts grpcresolver.BuildOptions) (*resolver, error) {
var fn func(context.Context, []string) ([]string, error)
switch target.Authority {
switch target.URL.Host {
case "vtctld":
fn = b.opts.Discovery.DiscoverVtctldAddrs
case "vtgate":
fn = b.opts.Discovery.DiscoverVTGateAddrs
default:
return nil, fmt.Errorf("%s: unsupported authority %s", logPrefix, target.Authority)
return nil, fmt.Errorf("%s: unsupported URL host %s", logPrefix, target.URL.Host)
}

var sc serviceconfig.Config
Expand All @@ -198,8 +200,8 @@ func (b *builder) build(target grpcresolver.Target, cc grpcresolver.ClientConn,
ctx, cancel := context.WithCancel(context.Background())

return &resolver{
component: target.Authority,
cluster: target.Scheme,
component: target.URL.Host,
cluster: target.URL.Scheme,
discoverAddrs: fn,
opts: b.opts,
cc: cc,
Expand Down

0 comments on commit 3d7ab09

Please sign in to comment.