From 54f280b3c9f1f2fe3174e025e6b7ef9bc20ffb7a Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Tue, 11 Feb 2020 17:24:59 -0800 Subject: [PATCH] Review comments #1. --- clientconn.go | 4 ++-- internal/{target => grpcutil}/target.go | 9 +++++---- internal/{target => grpcutil}/target_test.go | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) rename internal/{target => grpcutil}/target.go (84%) rename internal/{target => grpcutil}/target_test.go (94%) diff --git a/clientconn.go b/clientconn.go index 5eaf04a5e8ff..5edfad3340ba 100644 --- a/clientconn.go +++ b/clientconn.go @@ -39,7 +39,7 @@ import ( "google.golang.org/grpc/internal/backoff" "google.golang.org/grpc/internal/channelz" "google.golang.org/grpc/internal/grpcsync" - internaltarget "google.golang.org/grpc/internal/target" + "google.golang.org/grpc/internal/grpcutil" "google.golang.org/grpc/internal/transport" "google.golang.org/grpc/keepalive" "google.golang.org/grpc/resolver" @@ -242,7 +242,7 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn * } // Determine the resolver to use. - cc.parsedTarget = internaltarget.Parse(cc.target) + cc.parsedTarget = grpcutil.ParseTarget(cc.target) grpclog.Infof("parsed scheme: %q", cc.parsedTarget.Scheme) resolverBuilder := cc.getResolver(cc.parsedTarget.Scheme) if resolverBuilder == nil { diff --git a/internal/target/target.go b/internal/grpcutil/target.go similarity index 84% rename from internal/target/target.go rename to internal/grpcutil/target.go index 06066d3caf92..80b33cdaf905 100644 --- a/internal/target/target.go +++ b/internal/grpcutil/target.go @@ -16,8 +16,9 @@ * */ -// Package target provides functionality to parse target URI strings. -package target +// Package grpcutil provides a bunch of utility functions to be used across the +// gRPC codebase. +package grpcutil import ( "strings" @@ -35,12 +36,12 @@ func split2(s, sep string) (string, string, bool) { return spl[0], spl[1], true } -// Parse splits target into a resolver.Target struct containing scheme, +// ParseTarget splits target into a resolver.Target struct containing scheme, // authority and endpoint. // // If target is not a valid scheme://authority/endpoint, it returns {Endpoint: // target}. -func Parse(target string) (ret resolver.Target) { +func ParseTarget(target string) (ret resolver.Target) { var ok bool ret.Scheme, ret.Endpoint, ok = split2(target, "://") if !ok { diff --git a/internal/target/target_test.go b/internal/grpcutil/target_test.go similarity index 94% rename from internal/target/target_test.go rename to internal/grpcutil/target_test.go index 14bad2f7612c..92bdb63d213d 100644 --- a/internal/target/target_test.go +++ b/internal/grpcutil/target_test.go @@ -16,7 +16,7 @@ * */ -package target +package grpcutil import ( "testing" @@ -32,9 +32,9 @@ func TestParseTarget(t *testing.T) { {Scheme: "passthrough", Authority: "", Endpoint: "/unix/socket/address"}, } { str := test.Scheme + "://" + test.Authority + "/" + test.Endpoint - got := Parse(str) + got := ParseTarget(str) if got != test { - t.Errorf("Parse(%q) = %+v, want %+v", str, got, test) + t.Errorf("ParseTarget(%q) = %+v, want %+v", str, got, test) } } } @@ -71,9 +71,9 @@ func TestParseTargetString(t *testing.T) { {targetStr: "a//b", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "a//b"}}, {targetStr: "a://b", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "a://b"}}, } { - got := Parse(test.targetStr) + got := ParseTarget(test.targetStr) if got != test.want { - t.Errorf("Parse(%q) = %+v, want %+v", test.targetStr, got, test.want) + t.Errorf("ParseTarget(%q) = %+v, want %+v", test.targetStr, got, test.want) } } }