From 1e8f4287af406c90a26d554d02808ad309ef1287 Mon Sep 17 00:00:00 2001 From: cruel Date: Wed, 22 May 2024 21:12:21 +0800 Subject: [PATCH] contrib/registry/zookeeper: fix invalid searching prefix (#3598) --- contrib/registry/zookeeper/zookeeper_discovery.go | 2 +- contrib/registry/zookeeper/zookeeper_registrar.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/registry/zookeeper/zookeeper_discovery.go b/contrib/registry/zookeeper/zookeeper_discovery.go index c930a1ce3..53eee5288 100644 --- a/contrib/registry/zookeeper/zookeeper_discovery.go +++ b/contrib/registry/zookeeper/zookeeper_discovery.go @@ -19,7 +19,7 @@ import ( // Search searches and returns services with specified condition. func (r *Registry) Search(_ context.Context, in gsvc.SearchInput) ([]gsvc.Service, error) { - prefix := strings.TrimPrefix(strings.ReplaceAll(in.Prefix, "/", "-"), "-") + prefix := strings.Trim(strings.ReplaceAll(in.Prefix, "/", "-"), "-") instances, err, _ := r.group.Do(prefix, func() (interface{}, error) { serviceNamePath := path.Join(r.opts.namespace, prefix) servicesID, _, err := r.conn.Children(serviceNamePath) diff --git a/contrib/registry/zookeeper/zookeeper_registrar.go b/contrib/registry/zookeeper/zookeeper_registrar.go index a69060666..5b8a01817 100644 --- a/contrib/registry/zookeeper/zookeeper_registrar.go +++ b/contrib/registry/zookeeper/zookeeper_registrar.go @@ -31,7 +31,7 @@ func (r *Registry) Register(_ context.Context, service gsvc.Service) (gsvc.Servi r.opts.namespace, ) } - prefix := strings.TrimPrefix(strings.ReplaceAll(service.GetPrefix(), "/", "-"), "-") + prefix := strings.Trim(strings.ReplaceAll(service.GetPrefix(), "/", "-"), "-") servicePrefixPath := path.Join(r.opts.namespace, prefix) if err = r.ensureName(servicePrefixPath, []byte(""), 0); err != nil { return service, gerror.Wrapf(