diff --git a/internal/endpoint/endpoint.go b/internal/endpoint/endpoint.go index e4c9ef969..160b694f7 100644 --- a/internal/endpoint/endpoint.go +++ b/internal/endpoint/endpoint.go @@ -2,7 +2,6 @@ package endpoint import ( "net/url" - "strconv" ) // NewEndpoint new an Endpoint URL. @@ -18,10 +17,6 @@ func ParseEndpoint(endpoints []string, scheme string) (string, error) { return "", err } - // TODO: Compatibility processing - // Function is to convert grpc:/127.0.0.1/?isSecure=true into grpcs:/127.0.0.1/ - // It will be deleted in about a month - u = legacyURLToNew(u) if u.Scheme == scheme { return u.Host, nil } @@ -29,27 +24,6 @@ func ParseEndpoint(endpoints []string, scheme string) (string, error) { return "", nil } -func legacyURLToNew(u *url.URL) *url.URL { - if u.Scheme == "https" || u.Scheme == "grpcs" { - return u - } - if IsSecure(u) { - return &url.URL{Scheme: u.Scheme + "s", Host: u.Host} - } - return u -} - -// IsSecure parses isSecure for Endpoint URL. -// Note: It will be deleted after some time, -// unified use grpcs://127.0.0.1:8080 instead of grpc://127.0.0.1:8080?isSecure=true -func IsSecure(u *url.URL) bool { - ok, err := strconv.ParseBool(u.Query().Get("isSecure")) - if err != nil { - return false - } - return ok -} - // Scheme is the scheme of endpoint url. // examples: scheme="http",isSecure=true get "https" func Scheme(scheme string, isSecure bool) string { diff --git a/internal/endpoint/endpoint_test.go b/internal/endpoint/endpoint_test.go index e8870c800..c02878fd5 100644 --- a/internal/endpoint/endpoint_test.go +++ b/internal/endpoint/endpoint_test.go @@ -6,41 +6,6 @@ import ( "testing" ) -func TestEndPoint(t *testing.T) { - type args struct { - url *url.URL - } - tests := []struct { - name string - args args - want bool - }{ - // TODO: Add test cases. - { - name: "grpc://127.0.0.1?isSecure=false", - args: args{&url.URL{Scheme: "grpc", Host: "127.0.0.1", RawQuery: "isSecure=false"}}, - want: false, - }, - { - name: "grpc://127.0.0.1?isSecure=true", - args: args{&url.URL{Scheme: "grpc", Host: "127.0.0.1", RawQuery: "isSecure=true"}}, - want: true, - }, - { - name: "grpc://127.0.0.1", - args: args{&url.URL{Scheme: "grpc", Host: "127.0.0.1"}}, - want: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := IsSecure(tt.args.url); !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetQuery() = %v, want %v", got, tt.want) - } - }) - } -} - func TestNewEndpoint(t *testing.T) { type args struct { scheme string @@ -111,20 +76,6 @@ func TestParseEndpoint(t *testing.T) { want: "", wantErr: false, }, - - // Legacy - { - name: "google", - args: args{endpoints: []string{"grpc://www.google.com/?isSecure=true"}, scheme: "grpcs"}, - want: "www.google.com", - wantErr: false, - }, - { - name: "baidu", - args: args{endpoints: []string{"http://www.baidu.com/?isSecure=true"}, scheme: "https"}, - want: "www.baidu.com", - wantErr: false, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -140,56 +91,6 @@ func TestParseEndpoint(t *testing.T) { } } -func TestIsSecure(t *testing.T) { - tests := []struct { - url *url.URL - want bool - }{ - { - url: &url.URL{Scheme: "http", Host: "127.0.0.1"}, - want: false, - }, - { - url: &url.URL{Scheme: "http", Host: "127.0.0.1", RawQuery: "isSecure=false"}, - want: false, - }, - { - url: &url.URL{Scheme: "grpc", Host: "127.0.0.1", RawQuery: "isSecure=true"}, - want: true, - }, - } - for _, tt := range tests { - if got := IsSecure(tt.url); got != tt.want { - t.Errorf("IsSecure() = %v, want %v", got, tt.want) - } - } -} - -func TestLegacyURLToNew(t *testing.T) { - tests := []struct { - url *url.URL - want *url.URL - }{ - { - url: &url.URL{Scheme: "http", Host: "www.google.com", RawQuery: "isSecure=true"}, - want: &url.URL{Scheme: "https", Host: "www.google.com"}, - }, - { - url: &url.URL{Scheme: "https", Host: "www.google.com", RawQuery: "isSecure=true"}, - want: &url.URL{Scheme: "https", Host: "www.google.com", RawQuery: "isSecure=true"}, - }, - { - url: &url.URL{Scheme: "http", Host: "go-kratos.dev", RawQuery: "isSecure=false"}, - want: &url.URL{Scheme: "http", Host: "go-kratos.dev", RawQuery: "isSecure=false"}, - }, - } - for _, tt := range tests { - if got := legacyURLToNew(tt.url); !reflect.DeepEqual(got, tt.want) { - t.Errorf("legacyURLToNew() = %v, want %v", got, tt.want) - } - } -} - func TestSchema(t *testing.T) { tests := []struct { schema string