|
|
@ -75,18 +75,18 @@ func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstan |
|
|
|
data []byte |
|
|
|
data []byte |
|
|
|
err error |
|
|
|
err error |
|
|
|
) |
|
|
|
) |
|
|
|
if err = r.ensureName(r.opts.rootPath, []byte("")); err != nil { |
|
|
|
if err = r.ensureName(r.opts.rootPath, []byte(""), 0); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
serviceNamePath := path.Join(r.opts.rootPath, service.Name) |
|
|
|
serviceNamePath := path.Join(r.opts.rootPath, service.Name) |
|
|
|
if err = r.ensureName(serviceNamePath, []byte("")); err != nil { |
|
|
|
if err = r.ensureName(serviceNamePath, []byte(""), 0); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if data, err = json.Marshal(service); err != nil { |
|
|
|
if data, err = json.Marshal(service); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
servicePath := path.Join(serviceNamePath, service.ID) |
|
|
|
servicePath := path.Join(serviceNamePath, service.ID) |
|
|
|
if err = r.ensureName(servicePath, data); err != nil { |
|
|
|
if err = r.ensureName(servicePath, data, zk.FlagEphemeral); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
@ -176,13 +176,13 @@ func (r *Registry) resolve(ss *serviceSet) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ensureName ensure node exists, if not exist, create and set data
|
|
|
|
// ensureName ensure node exists, if not exist, create and set data
|
|
|
|
func (r *Registry) ensureName(path string, data []byte) error { |
|
|
|
func (r *Registry) ensureName(path string, data []byte, flags int32) error { |
|
|
|
exists, _, err := r.conn.Exists(path) |
|
|
|
exists, _, err := r.conn.Exists(path) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if !exists { |
|
|
|
if !exists { |
|
|
|
_, err := r.conn.Create(path, data, 0, zk.WorldACL(zk.PermAll)) |
|
|
|
_, err := r.conn.Create(path, data, flags, zk.WorldACL(zk.PermAll)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|