Skip to content

Commit

Permalink
fix consul and kitexhertz
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-Morgan committed Sep 11, 2024
1 parent 0eccb48 commit a7655f8
Show file tree
Hide file tree
Showing 24 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion registry/consul/consulhertz/example/basic/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulhertz/example/basic/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulhertz/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulhertz/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulhertz/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulkitex/consul_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulkitex/consul_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulkitex/consul_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion registry/consul/consulkitex/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions registry/consul/consulkitex/example/basic/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions registry/consul/consulkitex/example/basic/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion registry/consul/consulkitex/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion registry/consul/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cwgo-pkg/registry/consul
module github.com/cloudwego-contrib/cwgo-pkg/registry/consul

go 1.16

Expand Down
2 changes: 1 addition & 1 deletion registry/etcd/etcdkitex/etcd_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions registry/etcd/etcdkitex/etcd_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions registry/etcd/etcdkitex/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io/ioutil" //nolint
"time"

Expand Down Expand Up @@ -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)
}

0 comments on commit a7655f8

Please sign in to comment.