Merge branch 'openimsdk:main' into main

This commit is contained in:
chao 2024-12-27 16:44:33 +08:00 committed by GitHub
commit df063d29ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -314,7 +314,7 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, cf
configGroup.POST("/reset_config", cm.ResetConfig) configGroup.POST("/reset_config", cm.ResetConfig)
} }
{ {
r.POST("/restart", cm.Restart) r.POST("/restart", cm.CheckAdmin, cm.Restart)
} }
return r, nil return r, nil
} }

View File

@ -143,9 +143,22 @@ func (r *RootCmd) updateConfigFromEtcd(opts *CmdOpts) error {
} }
update := func(configFileName string, configStruct any) error { update := func(configFileName string, configStruct any) error {
ctx := context.TODO()
key := disetcd.BuildKey(configFileName) key := disetcd.BuildKey(configFileName)
etcdRes, err := r.etcdClient.Get(context.TODO(), key) etcdRes, err := r.etcdClient.Get(ctx, key)
if err != nil || etcdRes.Count == 0 { 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 return nil
} }
err = json.Unmarshal(etcdRes.Kvs[0].Value, configStruct) err = json.Unmarshal(etcdRes.Kvs[0].Value, configStruct)