Skip to content

Commit ee05627

Browse files
tpoundsdanielnelson
authored andcommitted
Enable gofmt code simplification (influxdata#4887)
1 parent 4a31183 commit ee05627

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+599
-599
lines changed

Diff for: Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PREFIX := /usr/local
1212
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
1313
COMMIT := $(shell git rev-parse --short HEAD)
1414
GOFILES ?= $(shell git ls-files '*.go')
15-
GOFMT ?= $(shell gofmt -l $(filter-out plugins/parsers/influx/machine.go, $(GOFILES)))
15+
GOFMT ?= $(shell gofmt -l -s $(filter-out plugins/parsers/influx/machine.go, $(GOFILES)))
1616
BUILDFLAGS ?=
1717

1818
ifdef GOBIN
@@ -55,7 +55,7 @@ test:
5555

5656
.PHONY: fmt
5757
fmt:
58-
@gofmt -w $(filter-out plugins/parsers/influx/machine.go, $(GOFILES))
58+
@gofmt -s -w $(filter-out plugins/parsers/influx/machine.go, $(GOFILES))
5959

6060
.PHONY: fmtcheck
6161
fmtcheck:

Diff for: cmd/telegraf/telegraf.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ func main() {
296296
switch {
297297
case *fOutputList:
298298
fmt.Println("Available Output Plugins:")
299-
for k, _ := range outputs.Outputs {
299+
for k := range outputs.Outputs {
300300
fmt.Printf(" %s\n", k)
301301
}
302302
return
303303
case *fInputList:
304304
fmt.Println("Available Input Plugins:")
305-
for k, _ := range inputs.Inputs {
305+
for k := range inputs.Inputs {
306306
fmt.Printf(" %s\n", k)
307307
}
308308
return

Diff for: internal/config/config_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func TestConfig_LoadSingleInputWithEnvVars(t *testing.T) {
3232
FieldDrop: []string{"other", "stuff"},
3333
FieldPass: []string{"some", "strings"},
3434
TagDrop: []models.TagFilter{
35-
models.TagFilter{
35+
{
3636
Name: "badtag",
3737
Filter: []string{"othertag"},
3838
},
3939
},
4040
TagPass: []models.TagFilter{
41-
models.TagFilter{
41+
{
4242
Name: "goodtag",
4343
Filter: []string{"mytag"},
4444
},
@@ -71,13 +71,13 @@ func TestConfig_LoadSingleInput(t *testing.T) {
7171
FieldDrop: []string{"other", "stuff"},
7272
FieldPass: []string{"some", "strings"},
7373
TagDrop: []models.TagFilter{
74-
models.TagFilter{
74+
{
7575
Name: "badtag",
7676
Filter: []string{"othertag"},
7777
},
7878
},
7979
TagPass: []models.TagFilter{
80-
models.TagFilter{
80+
{
8181
Name: "goodtag",
8282
Filter: []string{"mytag"},
8383
},
@@ -117,13 +117,13 @@ func TestConfig_LoadDirectory(t *testing.T) {
117117
FieldDrop: []string{"other", "stuff"},
118118
FieldPass: []string{"some", "strings"},
119119
TagDrop: []models.TagFilter{
120-
models.TagFilter{
120+
{
121121
Name: "badtag",
122122
Filter: []string{"othertag"},
123123
},
124124
},
125125
TagPass: []models.TagFilter{
126-
models.TagFilter{
126+
{
127127
Name: "goodtag",
128128
Filter: []string{"mytag"},
129129
},

Diff for: internal/models/filter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ func (f *Filter) Compile() error {
7979
return fmt.Errorf("Error compiling 'taginclude', %s", err)
8080
}
8181

82-
for i, _ := range f.TagDrop {
82+
for i := range f.TagDrop {
8383
f.TagDrop[i].filter, err = filter.Compile(f.TagDrop[i].Filter)
8484
if err != nil {
8585
return fmt.Errorf("Error compiling 'tagdrop', %s", err)
8686
}
8787
}
88-
for i, _ := range f.TagPass {
88+
for i := range f.TagPass {
8989
f.TagPass[i].filter, err = filter.Compile(f.TagPass[i].Filter)
9090
if err != nil {
9191
return fmt.Errorf("Error compiling 'tagpass', %s", err)

Diff for: internal/models/filter_test.go

+32-32
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestFilter_ApplyEmpty(t *testing.T) {
2424

2525
func TestFilter_ApplyTagsDontPass(t *testing.T) {
2626
filters := []TagFilter{
27-
TagFilter{
27+
{
2828
Name: "cpu",
2929
Filter: []string{"cpu-*"},
3030
},
@@ -244,11 +244,11 @@ func TestFilter_FieldDrop(t *testing.T) {
244244

245245
func TestFilter_TagPass(t *testing.T) {
246246
filters := []TagFilter{
247-
TagFilter{
247+
{
248248
Name: "cpu",
249249
Filter: []string{"cpu-*"},
250250
},
251-
TagFilter{
251+
{
252252
Name: "mem",
253253
Filter: []string{"mem_free"},
254254
}}
@@ -258,19 +258,19 @@ func TestFilter_TagPass(t *testing.T) {
258258
require.NoError(t, f.Compile())
259259

260260
passes := [][]*telegraf.Tag{
261-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-total"}},
262-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-0"}},
263-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-1"}},
264-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-2"}},
265-
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_free"}},
261+
{{Key: "cpu", Value: "cpu-total"}},
262+
{{Key: "cpu", Value: "cpu-0"}},
263+
{{Key: "cpu", Value: "cpu-1"}},
264+
{{Key: "cpu", Value: "cpu-2"}},
265+
{{Key: "mem", Value: "mem_free"}},
266266
}
267267

268268
drops := [][]*telegraf.Tag{
269-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cputotal"}},
270-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu0"}},
271-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu1"}},
272-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu2"}},
273-
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_used"}},
269+
{{Key: "cpu", Value: "cputotal"}},
270+
{{Key: "cpu", Value: "cpu0"}},
271+
{{Key: "cpu", Value: "cpu1"}},
272+
{{Key: "cpu", Value: "cpu2"}},
273+
{{Key: "mem", Value: "mem_used"}},
274274
}
275275

276276
for _, tags := range passes {
@@ -288,11 +288,11 @@ func TestFilter_TagPass(t *testing.T) {
288288

289289
func TestFilter_TagDrop(t *testing.T) {
290290
filters := []TagFilter{
291-
TagFilter{
291+
{
292292
Name: "cpu",
293293
Filter: []string{"cpu-*"},
294294
},
295-
TagFilter{
295+
{
296296
Name: "mem",
297297
Filter: []string{"mem_free"},
298298
}}
@@ -302,19 +302,19 @@ func TestFilter_TagDrop(t *testing.T) {
302302
require.NoError(t, f.Compile())
303303

304304
drops := [][]*telegraf.Tag{
305-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-total"}},
306-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-0"}},
307-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-1"}},
308-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-2"}},
309-
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_free"}},
305+
{{Key: "cpu", Value: "cpu-total"}},
306+
{{Key: "cpu", Value: "cpu-0"}},
307+
{{Key: "cpu", Value: "cpu-1"}},
308+
{{Key: "cpu", Value: "cpu-2"}},
309+
{{Key: "mem", Value: "mem_free"}},
310310
}
311311

312312
passes := [][]*telegraf.Tag{
313-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cputotal"}},
314-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu0"}},
315-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu1"}},
316-
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu2"}},
317-
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_used"}},
313+
{{Key: "cpu", Value: "cputotal"}},
314+
{{Key: "cpu", Value: "cpu0"}},
315+
{{Key: "cpu", Value: "cpu1"}},
316+
{{Key: "cpu", Value: "cpu2"}},
317+
{{Key: "mem", Value: "mem_used"}},
318318
}
319319

320320
for _, tags := range passes {
@@ -442,27 +442,27 @@ func TestFilter_FilterFieldPassAndDrop(t *testing.T) {
442442
// see: https://github.com/influxdata/telegraf/issues/2860
443443
func TestFilter_FilterTagsPassAndDrop(t *testing.T) {
444444
inputData := [][]*telegraf.Tag{
445-
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "1"}, &telegraf.Tag{Key: "tag2", Value: "3"}},
446-
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "1"}, &telegraf.Tag{Key: "tag2", Value: "2"}},
447-
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "2"}, &telegraf.Tag{Key: "tag2", Value: "1"}},
448-
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "4"}, &telegraf.Tag{Key: "tag2", Value: "1"}},
445+
{{Key: "tag1", Value: "1"}, {Key: "tag2", Value: "3"}},
446+
{{Key: "tag1", Value: "1"}, {Key: "tag2", Value: "2"}},
447+
{{Key: "tag1", Value: "2"}, {Key: "tag2", Value: "1"}},
448+
{{Key: "tag1", Value: "4"}, {Key: "tag2", Value: "1"}},
449449
}
450450

451451
expectedResult := []bool{false, true, false, false}
452452

453453
filterPass := []TagFilter{
454-
TagFilter{
454+
{
455455
Name: "tag1",
456456
Filter: []string{"1", "4"},
457457
},
458458
}
459459

460460
filterDrop := []TagFilter{
461-
TagFilter{
461+
{
462462
Name: "tag1",
463463
Filter: []string{"4"},
464464
},
465-
TagFilter{
465+
{
466466
Name: "tag2",
467467
Filter: []string{"3"},
468468
},

Diff for: plugins/inputs/bcache/bcache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func prettyToBytes(v string) uint64 {
5959
}
6060
var factor uint64
6161
factor = 1
62-
prefix := v[len(v)-1 : len(v)]
62+
prefix := v[len(v)-1:]
6363
if factors[prefix] != 0 {
6464
v = v[:len(v)-1]
6565
factor = factors[prefix]

Diff for: plugins/inputs/ceph/ceph.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func flatten(data interface{}) []*metric {
278278

279279
switch val := data.(type) {
280280
case float64:
281-
metrics = []*metric{&metric{make([]string, 0, 1), val}}
281+
metrics = []*metric{{make([]string, 0, 1), val}}
282282
case map[string]interface{}:
283283
metrics = make([]*metric, 0, len(val))
284284
for k, v := range val {

Diff for: plugins/inputs/ceph/ceph_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestGather(t *testing.T) {
8181
}()
8282

8383
findSockets = func(c *Ceph) ([]*socket, error) {
84-
return []*socket{&socket{"osd.1", typeOsd, ""}}, nil
84+
return []*socket{{"osd.1", typeOsd, ""}}, nil
8585
}
8686

8787
perfDump = func(binary string, s *socket) (string, error) {
@@ -190,17 +190,17 @@ type SockTest struct {
190190
}
191191

192192
var sockTestParams = []*SockTest{
193-
&SockTest{
193+
{
194194
osds: 2,
195195
mons: 2,
196196
},
197-
&SockTest{
197+
{
198198
mons: 1,
199199
},
200-
&SockTest{
200+
{
201201
osds: 1,
202202
},
203-
&SockTest{},
203+
{},
204204
}
205205

206206
var monPerfDump = `

Diff for: plugins/inputs/cgroup/cgroup_linux.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const valuePattern = "[\\d-]+"
173173

174174
var fileFormats = [...]fileFormat{
175175
// VAL\n
176-
fileFormat{
176+
{
177177
name: "Single value",
178178
pattern: "^" + valuePattern + "\n$",
179179
parser: func(measurement string, fields map[string]interface{}, b []byte) {
@@ -185,7 +185,7 @@ var fileFormats = [...]fileFormat{
185185
// VAL0\n
186186
// VAL1\n
187187
// ...
188-
fileFormat{
188+
{
189189
name: "New line separated values",
190190
pattern: "^(" + valuePattern + "\n){2,}$",
191191
parser: func(measurement string, fields map[string]interface{}, b []byte) {
@@ -197,7 +197,7 @@ var fileFormats = [...]fileFormat{
197197
},
198198
},
199199
// VAL0 VAL1 ...\n
200-
fileFormat{
200+
{
201201
name: "Space separated values",
202202
pattern: "^(" + valuePattern + " )+\n$",
203203
parser: func(measurement string, fields map[string]interface{}, b []byte) {
@@ -211,7 +211,7 @@ var fileFormats = [...]fileFormat{
211211
// KEY0 VAL0\n
212212
// KEY1 VAL1\n
213213
// ...
214-
fileFormat{
214+
{
215215
name: "New line separated key-space-value's",
216216
pattern: "^(" + keyPattern + " " + valuePattern + "\n)+$",
217217
parser: func(measurement string, fields map[string]interface{}, b []byte) {

Diff for: plugins/inputs/cloudwatch/cloudwatch_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (m *mockGatherCloudWatchClient) ListMetrics(params *cloudwatch.ListMetricsI
1818
Namespace: params.Namespace,
1919
MetricName: aws.String("Latency"),
2020
Dimensions: []*cloudwatch.Dimension{
21-
&cloudwatch.Dimension{
21+
{
2222
Name: aws.String("LoadBalancerName"),
2323
Value: aws.String("p-example"),
2424
},
@@ -100,7 +100,7 @@ func (m *mockSelectMetricsCloudWatchClient) ListMetrics(params *cloudwatch.ListM
100100
Namespace: aws.String("AWS/ELB"),
101101
MetricName: aws.String(m),
102102
Dimensions: []*cloudwatch.Dimension{
103-
&cloudwatch.Dimension{
103+
{
104104
Name: aws.String("LoadBalancerName"),
105105
Value: aws.String(lb),
106106
},
@@ -112,11 +112,11 @@ func (m *mockSelectMetricsCloudWatchClient) ListMetrics(params *cloudwatch.ListM
112112
Namespace: aws.String("AWS/ELB"),
113113
MetricName: aws.String(m),
114114
Dimensions: []*cloudwatch.Dimension{
115-
&cloudwatch.Dimension{
115+
{
116116
Name: aws.String("LoadBalancerName"),
117117
Value: aws.String(lb),
118118
},
119-
&cloudwatch.Dimension{
119+
{
120120
Name: aws.String("AvailabilityZone"),
121121
Value: aws.String(az),
122122
},
@@ -148,14 +148,14 @@ func TestSelectMetrics(t *testing.T) {
148148
Period: internalDuration,
149149
RateLimit: 200,
150150
Metrics: []*Metric{
151-
&Metric{
151+
{
152152
MetricNames: []string{"Latency", "RequestCount"},
153153
Dimensions: []*Dimension{
154-
&Dimension{
154+
{
155155
Name: "LoadBalancerName",
156156
Value: "*",
157157
},
158-
&Dimension{
158+
{
159159
Name: "AvailabilityZone",
160160
Value: "*",
161161
},

Diff for: plugins/inputs/consul/consul_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
var sampleChecks = []*api.HealthCheck{
11-
&api.HealthCheck{
11+
{
1212
Node: "localhost",
1313
CheckID: "foo.health123",
1414
Name: "foo.health",

Diff for: plugins/inputs/cpu/cpu_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func TestCPUCountIncrease(t *testing.T) {
163163

164164
mps.On("CPUTimes").Return(
165165
[]cpu.TimesStat{
166-
cpu.TimesStat{
166+
{
167167
CPU: "cpu0",
168168
},
169169
}, nil)
@@ -173,10 +173,10 @@ func TestCPUCountIncrease(t *testing.T) {
173173

174174
mps2.On("CPUTimes").Return(
175175
[]cpu.TimesStat{
176-
cpu.TimesStat{
176+
{
177177
CPU: "cpu0",
178178
},
179-
cpu.TimesStat{
179+
{
180180
CPU: "cpu1",
181181
},
182182
}, nil)

0 commit comments

Comments
 (0)