chore: slice loop replace (#20204)

Signed-off-by: guoguangwu <guoguangwug@gmail.com>
This commit is contained in:
guangwu
2024-05-07 18:19:15 +08:00
committed by GitHub
parent d4900e7d45
commit 23e3e4744d
7 changed files with 9 additions and 27 deletions
+1 -3
View File
@@ -77,9 +77,7 @@ func newCommonAlertQuery(tem *CommonAlertTerm) *monitorapi.CommonAlertQuery {
mq.Selects = append(mq.Selects, selectPart)
}
if len(tem.Filters) != 0 {
for _, filter := range tem.Filters {
mq.Tags = append(mq.Tags, filter)
}
mq.Tags = append(mq.Tags, tem.Filters...)
}
alertQ := new(monitorapi.AlertQuery)
@@ -201,9 +201,7 @@ func genMsgViaLang(ctx context.Context, p sNotifyParams) ([]npk.SNotifyMessage,
uidSet.Insert(id)
}
}
for _, uid := range uidSet.UnsortedList() {
reIds = append(reIds, uid)
}
reIds = append(reIds, uidSet.UnsortedList()...)
} else {
reIds = p.recipientId
}
+1 -3
View File
@@ -137,9 +137,7 @@ func newInvalidStructError(key string, err error) error {
jsonClientErr, ok := err.(*httputils.JSONClientError)
if ok {
errFmt += httputils.MsgTmplToFmt(jsonClientErr.Data.Id)
for _, f := range jsonClientErr.Data.Fields {
params = append(params, f)
}
params = append(params, jsonClientErr.Data.Fields...)
}
return newError(ERR_INVALID_VALUE, errFmt, params...)
}
@@ -76,9 +76,7 @@ func (manager *NotificationManager) Send(s *mcclient.ClientSession, msg SNotifyM
uidSet.Insert(id)
}
}
for _, uid := range uidSet.UnsortedList() {
receiverIds = append(receiverIds, uid)
}
receiverIds = append(receiverIds, uidSet.UnsortedList()...)
}
receiverIds = append(receiverIds, msg.Uid...)
+3 -9
View File
@@ -72,15 +72,9 @@ func parsePolicyRule(rule string) (*PolicyRule, error) {
APIGroups: []string{},
Resources: []string{},
}
for _, group := range strings.Split(groupStr, ",") {
ret.APIGroups = append(ret.APIGroups, group)
}
for _, res := range strings.Split(resourceStr, ",") {
ret.Resources = append(ret.Resources, res)
}
for _, verb := range strings.Split(verbStr, ",") {
ret.Verbs = append(ret.Verbs, verb)
}
ret.APIGroups = append(ret.APIGroups, strings.Split(groupStr, ",")...)
ret.Resources = append(ret.Resources, strings.Split(resourceStr, ",")...)
ret.Verbs = append(ret.Verbs, strings.Split(verbStr, ",")...)
return ret, nil
}
+1 -3
View File
@@ -348,9 +348,7 @@ func ListAllResources(manager modulebase.Manager, params *jsonutils.JSONDict) ([
if err != nil {
return nil, errors.Wrapf(err, "list %s resources with params %s", manager.KeyString(), params.String())
}
for _, data := range result.Data {
objs = append(objs, data)
}
objs = append(objs, result.Data...)
total := result.Total
count = count + len(result.Data)
if count >= total {
+1 -3
View File
@@ -56,9 +56,7 @@ func (c *BaseCommand) GetClientSession() *mcclient.ClientSession {
}
func (c *BaseCommand) AppendArgs(args ...string) *BaseCommand {
for _, arg := range args {
c.args = append(c.args, arg)
}
c.args = append(c.args, args...)
return c
}