From a7655f833fa8d387a786809785988b0a190aa6ee Mon Sep 17 00:00:00 2001 From: smx-Morgan <1048492656@qq.com> Date: Wed, 11 Sep 2024 16:50:22 +0800 Subject: [PATCH] fix consul and kitexhertz --- registry/consul/consulhertz/example/basic/client/main.go | 2 +- registry/consul/consulhertz/example/basic/server/main.go | 2 +- .../consul/consulhertz/example/custom-config/client/main.go | 2 +- .../consul/consulhertz/example/custom-config/server/main.go | 2 +- registry/consul/consulhertz/registry.go | 2 +- registry/consul/consulhertz/resolver.go | 2 +- registry/consul/consulhertz/utils.go | 2 +- registry/consul/consulkitex/consul_registry.go | 2 +- registry/consul/consulkitex/consul_resolver.go | 2 +- registry/consul/consulkitex/consul_resolver_test.go | 2 +- registry/consul/consulkitex/consul_test.go | 2 +- registry/consul/consulkitex/example/basic/client/main.go | 6 +++--- registry/consul/consulkitex/example/basic/server/main.go | 6 +++--- .../consul/consulkitex/example/custom-config/client/main.go | 6 +++--- .../consul/consulkitex/example/custom-config/server/main.go | 6 +++--- .../consulkitex/example/hello/kitex_gen/api/hello/client.go | 2 +- .../consulkitex/example/hello/kitex_gen/api/hello/hello.go | 2 +- .../example/hello/kitex_gen/api/hello/invoker.go | 2 +- .../consulkitex/example/hello/kitex_gen/api/hello/server.go | 2 +- registry/consul/consulkitex/utils.go | 2 +- registry/consul/go.mod | 2 +- registry/etcd/etcdkitex/etcd_resolver.go | 2 +- registry/etcd/etcdkitex/etcd_resolver_test.go | 6 ++---- registry/etcd/etcdkitex/option.go | 6 ++++++ 24 files changed, 38 insertions(+), 34 deletions(-) diff --git a/registry/consul/consulhertz/example/basic/client/main.go b/registry/consul/consulhertz/example/basic/client/main.go index 921124f..374f2b4 100644 --- a/registry/consul/consulhertz/example/basic/client/main.go +++ b/registry/consul/consulhertz/example/basic/client/main.go @@ -18,7 +18,7 @@ import ( "context" "log" - consul "github.com/cwgo-pkg/registry/consul/consulhertz" + consul "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulhertz" "github.com/cloudwego/hertz/pkg/app/client" "github.com/cloudwego/hertz/pkg/app/middlewares/client/sd" diff --git a/registry/consul/consulhertz/example/basic/server/main.go b/registry/consul/consulhertz/example/basic/server/main.go index 1737f14..68530eb 100644 --- a/registry/consul/consulhertz/example/basic/server/main.go +++ b/registry/consul/consulhertz/example/basic/server/main.go @@ -20,7 +20,7 @@ import ( "net" "sync" - "github.com/cwgo-pkg/registry/consul/consulhertz" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulhertz" "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/app/server" diff --git a/registry/consul/consulhertz/example/custom-config/client/main.go b/registry/consul/consulhertz/example/custom-config/client/main.go index 14c9eaa..4d6e947 100644 --- a/registry/consul/consulhertz/example/custom-config/client/main.go +++ b/registry/consul/consulhertz/example/custom-config/client/main.go @@ -22,7 +22,7 @@ import ( "net" "time" - "github.com/cwgo-pkg/registry/consul/consulhertz" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulhertz" "github.com/cloudwego/hertz/pkg/app/client" "github.com/cloudwego/hertz/pkg/app/client/discovery" diff --git a/registry/consul/consulhertz/example/custom-config/server/main.go b/registry/consul/consulhertz/example/custom-config/server/main.go index 7067c33..ee5c5d3 100644 --- a/registry/consul/consulhertz/example/custom-config/server/main.go +++ b/registry/consul/consulhertz/example/custom-config/server/main.go @@ -20,7 +20,7 @@ import ( "net" "sync" - "github.com/cwgo-pkg/registry/consul/consulhertz" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulhertz" "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/app/server" diff --git a/registry/consul/consulhertz/registry.go b/registry/consul/consulhertz/registry.go index 0fa7310..25bb0b8 100644 --- a/registry/consul/consulhertz/registry.go +++ b/registry/consul/consulhertz/registry.go @@ -19,8 +19,8 @@ import ( "fmt" "net" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" "github.com/cloudwego/hertz/pkg/app/server/registry" - "github.com/cwgo-pkg/registry/consul/internal" "github.com/hashicorp/consul/api" ) diff --git a/registry/consul/consulhertz/resolver.go b/registry/consul/consulhertz/resolver.go index ac50a76..0f4476b 100644 --- a/registry/consul/consulhertz/resolver.go +++ b/registry/consul/consulhertz/resolver.go @@ -19,7 +19,7 @@ import ( "fmt" "net" - "github.com/cwgo-pkg/registry/consul/internal" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" "github.com/cloudwego/hertz/pkg/app/client/discovery" "github.com/hashicorp/consul/api" diff --git a/registry/consul/consulhertz/utils.go b/registry/consul/consulhertz/utils.go index 6fe0fa3..1188f08 100644 --- a/registry/consul/consulhertz/utils.go +++ b/registry/consul/consulhertz/utils.go @@ -18,8 +18,8 @@ import ( "errors" "fmt" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" "github.com/cloudwego/hertz/pkg/app/server/registry" - "github.com/cwgo-pkg/registry/consul/internal" ) var errIllegalTagChar = errors.New("illegal tag character") diff --git a/registry/consul/consulkitex/consul_registry.go b/registry/consul/consulkitex/consul_registry.go index 69b2e17..74755c8 100644 --- a/registry/consul/consulkitex/consul_registry.go +++ b/registry/consul/consulkitex/consul_registry.go @@ -20,8 +20,8 @@ import ( "errors" "fmt" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" "github.com/cloudwego/kitex/pkg/registry" - "github.com/cwgo-pkg/registry/consul/internal" "github.com/hashicorp/consul/api" ) diff --git a/registry/consul/consulkitex/consul_resolver.go b/registry/consul/consulkitex/consul_resolver.go index d8277e6..000f8cd 100644 --- a/registry/consul/consulkitex/consul_resolver.go +++ b/registry/consul/consulkitex/consul_resolver.go @@ -21,9 +21,9 @@ import ( "errors" "fmt" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" "github.com/cloudwego/kitex/pkg/discovery" "github.com/cloudwego/kitex/pkg/rpcinfo" - "github.com/cwgo-pkg/registry/consul/internal" "github.com/hashicorp/consul/api" ) diff --git a/registry/consul/consulkitex/consul_resolver_test.go b/registry/consul/consulkitex/consul_resolver_test.go index bdaf163..72b64c1 100644 --- a/registry/consul/consulkitex/consul_resolver_test.go +++ b/registry/consul/consulkitex/consul_resolver_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "github.com/cwgo-pkg/registry/consul/internal" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" ) func TestSplitTags(t *testing.T) { diff --git a/registry/consul/consulkitex/consul_test.go b/registry/consul/consulkitex/consul_test.go index bffe094..68a9b00 100644 --- a/registry/consul/consulkitex/consul_test.go +++ b/registry/consul/consulkitex/consul_test.go @@ -26,7 +26,7 @@ import ( "testing" "time" - "github.com/cwgo-pkg/registry/consul/internal" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" "github.com/cloudwego/kitex/pkg/discovery" "github.com/cloudwego/kitex/pkg/registry" diff --git a/registry/consul/consulkitex/example/basic/client/main.go b/registry/consul/consulkitex/example/basic/client/main.go index d7be5ba..f576395 100644 --- a/registry/consul/consulkitex/example/basic/client/main.go +++ b/registry/consul/consulkitex/example/basic/client/main.go @@ -21,12 +21,12 @@ import ( "log" "time" - consul "github.com/cwgo-pkg/registry/consul/consulkitex" + consul "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex" "github.com/cloudwego/kitex/client" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" ) func main() { diff --git a/registry/consul/consulkitex/example/basic/server/main.go b/registry/consul/consulkitex/example/basic/server/main.go index 308956e..33e4a8b 100644 --- a/registry/consul/consulkitex/example/basic/server/main.go +++ b/registry/consul/consulkitex/example/basic/server/main.go @@ -20,11 +20,11 @@ import ( "context" "log" + consul "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" "github.com/cloudwego/kitex/pkg/registry" "github.com/cloudwego/kitex/server" - consul "github.com/cwgo-pkg/registry/consul/consulkitex" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" ) type HelloImpl struct{} diff --git a/registry/consul/consulkitex/example/custom-config/client/main.go b/registry/consul/consulkitex/example/custom-config/client/main.go index cc84fc1..4fce217 100644 --- a/registry/consul/consulkitex/example/custom-config/client/main.go +++ b/registry/consul/consulkitex/example/custom-config/client/main.go @@ -21,12 +21,12 @@ import ( "log" "time" - consul "github.com/cwgo-pkg/registry/consul/consulkitex" + consul "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex" consulapi "github.com/hashicorp/consul/api" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" "github.com/cloudwego/kitex/client" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" ) func main() { diff --git a/registry/consul/consulkitex/example/custom-config/server/main.go b/registry/consul/consulkitex/example/custom-config/server/main.go index 4130bd0..5c13ae1 100644 --- a/registry/consul/consulkitex/example/custom-config/server/main.go +++ b/registry/consul/consulkitex/example/custom-config/server/main.go @@ -20,13 +20,13 @@ import ( "context" "log" - consul "github.com/cwgo-pkg/registry/consul/consulkitex" + consul "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex" consulapi "github.com/hashicorp/consul/api" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" "github.com/cloudwego/kitex/pkg/registry" "github.com/cloudwego/kitex/server" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api/hello" ) type HelloImpl struct{} diff --git a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/client.go b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/client.go index 8b4f3d9..2ecd7fe 100644 --- a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/client.go +++ b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/client.go @@ -5,9 +5,9 @@ package hello import ( "context" + api "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" client "github.com/cloudwego/kitex/client" callopt "github.com/cloudwego/kitex/client/callopt" - api "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" ) // Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. diff --git a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/hello.go b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/hello.go index f2a7a3f..abe6667 100644 --- a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/hello.go +++ b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/hello.go @@ -5,9 +5,9 @@ package hello import ( "context" + api "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" client "github.com/cloudwego/kitex/client" kitex "github.com/cloudwego/kitex/pkg/serviceinfo" - api "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" ) func serviceInfo() *kitex.ServiceInfo { diff --git a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/invoker.go b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/invoker.go index 07e5c77..6a52f84 100644 --- a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/invoker.go +++ b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/invoker.go @@ -3,8 +3,8 @@ package hello import ( + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" server "github.com/cloudwego/kitex/server" - "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" ) // NewInvoker creates a server.Invoker with the given handler and options. diff --git a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/server.go b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/server.go index 2c5a193..aa53988 100644 --- a/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/server.go +++ b/registry/consul/consulkitex/example/hello/kitex_gen/api/hello/server.go @@ -2,8 +2,8 @@ package hello import ( + api "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" server "github.com/cloudwego/kitex/server" - api "github.com/cwgo-pkg/registry/consul/consulkitex/example/hello/kitex_gen/api" ) // NewServer creates a server.Server with the given handler and options. diff --git a/registry/consul/consulkitex/utils.go b/registry/consul/consulkitex/utils.go index 775daf8..79e2df6 100644 --- a/registry/consul/consulkitex/utils.go +++ b/registry/consul/consulkitex/utils.go @@ -19,8 +19,8 @@ package consul import ( "fmt" + "github.com/cloudwego-contrib/cwgo-pkg/registry/consul/internal" "github.com/cloudwego/kitex/pkg/registry" - "github.com/cwgo-pkg/registry/consul/internal" ) func getServiceId(info *registry.Info) (string, error) { diff --git a/registry/consul/go.mod b/registry/consul/go.mod index 2b6f0e5..d36ac34 100644 --- a/registry/consul/go.mod +++ b/registry/consul/go.mod @@ -1,4 +1,4 @@ -module github.com/cwgo-pkg/registry/consul +module github.com/cloudwego-contrib/cwgo-pkg/registry/consul go 1.16 diff --git a/registry/etcd/etcdkitex/etcd_resolver.go b/registry/etcd/etcdkitex/etcd_resolver.go index fe3bc4a..934d515 100644 --- a/registry/etcd/etcdkitex/etcd_resolver.go +++ b/registry/etcd/etcdkitex/etcd_resolver.go @@ -85,7 +85,7 @@ func (e *etcdResolver) Target(ctx context.Context, target rpcinfo.EndpointInfo) // Resolve implements the Resolver interface. func (e *etcdResolver) Resolve(ctx context.Context, desc string) (discovery.Result, error) { - prefix := internal.ServiceKeyPrefix(e.prefix, desc) + prefix := serviceKeyPrefix(e.prefix, desc) resp, err := e.etcdClient.Get(ctx, prefix, clientv3.WithPrefix()) if err != nil { return discovery.Result{}, err diff --git a/registry/etcd/etcdkitex/etcd_resolver_test.go b/registry/etcd/etcdkitex/etcd_resolver_test.go index 49f3839..91ec749 100644 --- a/registry/etcd/etcdkitex/etcd_resolver_test.go +++ b/registry/etcd/etcdkitex/etcd_resolver_test.go @@ -32,8 +32,6 @@ import ( "testing" "time" - "github.com/cloudwego-contrib/cwgo-pkg/registry/etcd/internal" - "github.com/cloudwego/kitex/pkg/discovery" "github.com/cloudwego/kitex/pkg/registry" "github.com/cloudwego/kitex/pkg/rpcinfo" @@ -556,7 +554,7 @@ func TestEtcdResolverWithEtcdPrefix(t *testing.T) { }, } require.Equal(t, expected, result) - prefix := internal.ServiceKeyPrefix(rs.(*etcdResolver).GetPrefix(), info.ServiceName) + prefix := serviceKeyPrefix(rs.(*etcdResolver).GetPrefix(), info.ServiceName) println(prefix) require.Equal(t, fmt.Sprintf(tpl+"/%v/", info.ServiceName), prefix) } @@ -615,7 +613,7 @@ func TestEtcdResolverWithEtcdPrefix2(t *testing.T) { }, } require.Equal(t, expected, result) - prefix := internal.ServiceKeyPrefix(rs.(*etcdResolver).GetPrefix(), info.ServiceName) + prefix := serviceKeyPrefix(rs.(*etcdResolver).GetPrefix(), info.ServiceName) println(prefix) require.Equal(t, fmt.Sprintf("kitex/registry-etcd/%v/", info.ServiceName), prefix) } diff --git a/registry/etcd/etcdkitex/option.go b/registry/etcd/etcdkitex/option.go index 1eb03a7..7c19831 100644 --- a/registry/etcd/etcdkitex/option.go +++ b/registry/etcd/etcdkitex/option.go @@ -18,6 +18,7 @@ import ( "crypto/tls" "crypto/x509" "errors" + "fmt" "io/ioutil" //nolint "time" @@ -94,3 +95,8 @@ func WithDefaultWeight(defaultWeight int) Option { cfg.DefaultWeight = defaultWeight } } + +func serviceKeyPrefix(prefix string, serviceName string) string { + prefix = prefix + "/%v/" + return fmt.Sprintf(prefix, serviceName) +}