Skip to content

Commit

Permalink
fix(rpc): rpc client selector
Browse files Browse the repository at this point in the history
grpc/grpc-go#4717
https://github.com/grpc/grpc-go/releases/tag/v1.42.0
grpc/grpc-go#4817
从 1.42.0 之后,grpc-go 使用 url.Parse 来解析 dial target ,即 "scheme://xxx/xxx" , 之前的 secheme 含有非法字符下划线会导致解析失败。
  • Loading branch information
Allenxuxu committed Dec 11, 2021
1 parent 36206cc commit 82b0641
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rpc/client/resolver/resolver.go
Expand Up @@ -11,7 +11,7 @@ import (
"google.golang.org/grpc/resolver"
)

// "stark_registry:///{service}"
// "stark-registry:///{service}"
type builder struct {
scheme string
selector *atomic.Value
Expand Down
2 changes: 1 addition & 1 deletion rpc/client/selector/registry/registry_selector.go
Expand Up @@ -12,7 +12,7 @@ import (
"google.golang.org/grpc/resolver"
)

const scheme = "stark_registry"
const scheme = "stark-registry"

var _selector atomic.Value

Expand Down
10 changes: 10 additions & 0 deletions rpc/client/selector/registry/registry_selector_test.go
@@ -1,6 +1,8 @@
package registry

import (
"fmt"
"net/url"
"testing"

"github.com/Allenxuxu/stark/rpc/client/selector"
Expand Down Expand Up @@ -82,3 +84,11 @@ func TestRegistrySelectorFilter(t *testing.T) {
assert.Equal(t, service[0].Name, "foo")
assert.Equal(t, service[0].Version, version)
}

func Test_schema(t *testing.T) {
_, err := url.Parse(fmt.Sprintf("%s:///%s", "stark_registry", "test"))
assert.Error(t, err)

_, err = url.Parse(fmt.Sprintf("%s:///%s", "stark-registry", "test"))
assert.NoError(t, err)
}
2 changes: 1 addition & 1 deletion rpc/client/selector/static/static_selector.go
Expand Up @@ -11,7 +11,7 @@ import (
"google.golang.org/grpc/resolver"
)

const scheme = "stark_static"
const scheme = "stark-static"

var _selector atomic.Value

Expand Down

0 comments on commit 82b0641

Please sign in to comment.