From edcfb7f17aea6db0dea7e2115fdafe71d9961209 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Wed, 12 Jul 2023 14:08:01 +0800 Subject: [PATCH] chore: slice replace loop --- cmd/bosun/conf/notify.go | 4 +--- cmd/bosun/sched/host.go | 4 +--- cmd/bosun/sched/notify.go | 4 +--- cmd/bosun/sched/sched.go | 4 +--- cmd/scollector/collectors/aws.go | 8 ++------ cmd/tsdbrelay/denormalize/denormalization.go | 4 +--- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/cmd/bosun/conf/notify.go b/cmd/bosun/conf/notify.go index 5ec6b9eacb..a21d00381c 100644 --- a/cmd/bosun/conf/notify.go +++ b/cmd/bosun/conf/notify.go @@ -299,9 +299,7 @@ func (p *PreparedEmail) Send(c SystemConfProvider) error { e := email.NewEmail() e.From = c.GetEmailFrom() - for _, a := range p.To { - e.To = append(e.To, a) - } + e.To = append(e.To, p.To...) e.Subject = p.Subject e.HTML = []byte(p.Body) for _, a := range p.Attachments { diff --git a/cmd/bosun/sched/host.go b/cmd/bosun/sched/host.go index a905163f38..44daf65718 100644 --- a/cmd/bosun/sched/host.go +++ b/cmd/bosun/sched/host.go @@ -415,9 +415,7 @@ func (s *Schedule) Host(filter string) (map[string]*HostData, error) { if err != nil { slog.Errorf("error unmarshalling addresses for host %s, interface %s while generating host api: %s", host.Name, m.Tags["iface"], err) } - for _, address := range addresses { - iface.IPAddresses = append(iface.IPAddresses, address) - } + iface.IPAddresses = append(iface.IPAddresses, addresses...) } case "cdpCacheEntries": if iface != nil { diff --git a/cmd/bosun/sched/notify.go b/cmd/bosun/sched/notify.go index 50edb61cc7..d12bb085bf 100644 --- a/cmd/bosun/sched/notify.go +++ b/cmd/bosun/sched/notify.go @@ -251,9 +251,7 @@ func (s *Schedule) ActionNotify(at models.ActionType, user, message string, aks } } else { incidents := []*models.IncidentState{} - for _, state := range states { - incidents = append(incidents, state) - } + incidents = append(incidents, states...) not.NotifyAction(at, groupKey.template, s.SystemConf, incidents, user, message, s.RuleConf) } } diff --git a/cmd/bosun/sched/sched.go b/cmd/bosun/sched/sched.go index 8e591236dc..80bdd0b4c9 100644 --- a/cmd/bosun/sched/sched.go +++ b/cmd/bosun/sched/sched.go @@ -305,9 +305,7 @@ func (states States) GroupSets(minGroup int) map[string]models.AlertKeys { for a, aks := range groupedByAlert { if len(aks) >= minGroup { group := models.AlertKeys{} - for _, ak := range aks { - group = append(group, ak) - } + group = append(group, aks...) groups[a] = group } } diff --git a/cmd/scollector/collectors/aws.go b/cmd/scollector/collectors/aws.go index 4c39eca74f..3fd6dda34b 100644 --- a/cmd/scollector/collectors/aws.go +++ b/cmd/scollector/collectors/aws.go @@ -112,9 +112,7 @@ func awsGetInstances(ecc ec2.EC2) ([]*ec2.Instance, error) { return nil, fmt.Errorf("unable to describe EC2 Instances") } for _, reservation := range resp.Reservations { - for _, instance := range reservation.Instances { - instancelist = append(instancelist, instance) - } + instancelist = append(instancelist, reservation.Instances...) } return instancelist, nil } @@ -125,9 +123,7 @@ func awsGetLoadBalancers(lb elb.ELB) ([]*elb.LoadBalancerDescription, error) { if err != nil { return nil, fmt.Errorf("unable to describe ELB Balancers") } - for _, loadBalancer := range resp.LoadBalancerDescriptions { - lbList = append(lbList, loadBalancer) - } + lbList = append(lbList, resp.LoadBalancerDescriptions...) return lbList, nil } diff --git a/cmd/tsdbrelay/denormalize/denormalization.go b/cmd/tsdbrelay/denormalize/denormalization.go index f5b614bf79..ecebe3d4c9 100644 --- a/cmd/tsdbrelay/denormalize/denormalization.go +++ b/cmd/tsdbrelay/denormalize/denormalization.go @@ -37,9 +37,7 @@ func ParseDenormalizationRules(config string) (map[string]*DenormalizationRule, return nil, fmt.Errorf("Denormalization rules must have at least one tag name specified.") } rule := &DenormalizationRule{Metric: parts[0]} - for _, part := range parts[1:] { - rule.TagNames = append(rule.TagNames, part) - } + rule.TagNames = append(rule.TagNames, parts[1:]...) log.Println("Denormalizing", rule) m[rule.Metric] = rule }