Skip to content

Commit

Permalink
Merge branch 'openimsdk:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao authored Dec 27, 2024
2 parents 9f1fff6 + 930a9fd commit df063d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, cf
configGroup.POST("/reset_config", cm.ResetConfig)
}
{
r.POST("/restart", cm.Restart)
r.POST("/restart", cm.CheckAdmin, cm.Restart)
}
return r, nil
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/common/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,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 df063d2

Please sign in to comment.