Skip to content

Commit

Permalink
feat: config center
Browse files Browse the repository at this point in the history
  • Loading branch information
icey-yu committed Dec 27, 2024
1 parent 76f3b69 commit 1c1360e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/common/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,22 @@ func (r *RootCmd) updateConfigFromEtcd(opts *CmdOpts) error {
}

update := func(configFileName string, configStruct any) error {
ctx := context.TODO()
key := disetcd.BuildKey(configFileName)
etcdRes, err := r.etcdClient.Get(context.TODO(), key)
if err != nil || etcdRes.Count == 0 {
etcdRes, err := r.etcdClient.Get(ctx, key)
if err != nil {
log.ZWarn(ctx, "root cmd updateConfigFromEtcd, etcd Get err: %v", errs.Wrap(err))
return nil
}
if etcdRes.Count == 0 {
data, err := json.Marshal(configStruct)
if err != nil {
return errs.ErrArgs.WithDetail(err.Error()).Wrap()
}
_, err = r.etcdClient.Put(ctx, disetcd.BuildKey(configFileName), string(data))
if err != nil {
log.ZWarn(ctx, "root cmd updateConfigFromEtcd, etcd Put err: %v", errs.Wrap(err))
}
return nil
}
err = json.Unmarshal(etcdRes.Kvs[0].Value, configStruct)
Expand Down

0 comments on commit 1c1360e

Please sign in to comment.