瀏覽代碼

refactor: 优化注册中心的Namespace处理

lihf 3 月之前
父節點
當前提交
598c840e6d
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      registry/registry.go

+ 2 - 2
registry/registry.go

@@ -33,7 +33,7 @@ func Context(ctx context.Context) Option {
 
 // Namespace with registry namespace.
 func Namespace(ns string) Option {
-	return func(o *options) { o.namespace = fmt.Sprintf("/%s/naming", ns) }
+	return func(o *options) { o.namespace = ns }
 }
 
 // RegisterTTL with register ttl.
@@ -79,7 +79,7 @@ func New(client *clientv3.Client, opts ...Option) (r *Registry) {
 
 // Register the registration.
 func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error {
-	key := fmt.Sprintf("%s/%s/%s", r.opts.namespace, service.Name, service.ID)
+	key := fmt.Sprintf("/%s/naming/%s/%s", r.opts.namespace, service.Name, service.ID)
 	value, err := marshal(service)
 	if err != nil {
 		return err