Skip to content

Commit

Permalink
Enable gofmt code simplification (influxdata#4887)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpounds authored and danielnelson committed Oct 19, 2018
1 parent 4a31183 commit ee05627
Show file tree
Hide file tree
Showing 59 changed files with 599 additions and 599 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PREFIX := /usr/local
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git rev-parse --short HEAD)
GOFILES ?= $(shell git ls-files '*.go')
GOFMT ?= $(shell gofmt -l $(filter-out plugins/parsers/influx/machine.go, $(GOFILES)))
GOFMT ?= $(shell gofmt -l -s $(filter-out plugins/parsers/influx/machine.go, $(GOFILES)))
BUILDFLAGS ?=

ifdef GOBIN
Expand Down Expand Up @@ -55,7 +55,7 @@ test:

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

.PHONY: fmtcheck
fmtcheck:
Expand Down
4 changes: 2 additions & 2 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ func main() {
switch {
case *fOutputList:
fmt.Println("Available Output Plugins:")
for k, _ := range outputs.Outputs {
for k := range outputs.Outputs {
fmt.Printf(" %s\n", k)
}
return
case *fInputList:
fmt.Println("Available Input Plugins:")
for k, _ := range inputs.Inputs {
for k := range inputs.Inputs {
fmt.Printf(" %s\n", k)
}
return
Expand Down
12 changes: 6 additions & 6 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func TestConfig_LoadSingleInputWithEnvVars(t *testing.T) {
FieldDrop: []string{"other", "stuff"},
FieldPass: []string{"some", "strings"},
TagDrop: []models.TagFilter{
models.TagFilter{
{
Name: "badtag",
Filter: []string{"othertag"},
},
},
TagPass: []models.TagFilter{
models.TagFilter{
{
Name: "goodtag",
Filter: []string{"mytag"},
},
Expand Down Expand Up @@ -71,13 +71,13 @@ func TestConfig_LoadSingleInput(t *testing.T) {
FieldDrop: []string{"other", "stuff"},
FieldPass: []string{"some", "strings"},
TagDrop: []models.TagFilter{
models.TagFilter{
{
Name: "badtag",
Filter: []string{"othertag"},
},
},
TagPass: []models.TagFilter{
models.TagFilter{
{
Name: "goodtag",
Filter: []string{"mytag"},
},
Expand Down Expand Up @@ -117,13 +117,13 @@ func TestConfig_LoadDirectory(t *testing.T) {
FieldDrop: []string{"other", "stuff"},
FieldPass: []string{"some", "strings"},
TagDrop: []models.TagFilter{
models.TagFilter{
{
Name: "badtag",
Filter: []string{"othertag"},
},
},
TagPass: []models.TagFilter{
models.TagFilter{
{
Name: "goodtag",
Filter: []string{"mytag"},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/models/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func (f *Filter) Compile() error {
return fmt.Errorf("Error compiling 'taginclude', %s", err)
}

for i, _ := range f.TagDrop {
for i := range f.TagDrop {
f.TagDrop[i].filter, err = filter.Compile(f.TagDrop[i].Filter)
if err != nil {
return fmt.Errorf("Error compiling 'tagdrop', %s", err)
}
}
for i, _ := range f.TagPass {
for i := range f.TagPass {
f.TagPass[i].filter, err = filter.Compile(f.TagPass[i].Filter)
if err != nil {
return fmt.Errorf("Error compiling 'tagpass', %s", err)
Expand Down
64 changes: 32 additions & 32 deletions internal/models/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestFilter_ApplyEmpty(t *testing.T) {

func TestFilter_ApplyTagsDontPass(t *testing.T) {
filters := []TagFilter{
TagFilter{
{
Name: "cpu",
Filter: []string{"cpu-*"},
},
Expand Down Expand Up @@ -244,11 +244,11 @@ func TestFilter_FieldDrop(t *testing.T) {

func TestFilter_TagPass(t *testing.T) {
filters := []TagFilter{
TagFilter{
{
Name: "cpu",
Filter: []string{"cpu-*"},
},
TagFilter{
{
Name: "mem",
Filter: []string{"mem_free"},
}}
Expand All @@ -258,19 +258,19 @@ func TestFilter_TagPass(t *testing.T) {
require.NoError(t, f.Compile())

passes := [][]*telegraf.Tag{
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-total"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-0"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-1"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-2"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_free"}},
{{Key: "cpu", Value: "cpu-total"}},
{{Key: "cpu", Value: "cpu-0"}},
{{Key: "cpu", Value: "cpu-1"}},
{{Key: "cpu", Value: "cpu-2"}},
{{Key: "mem", Value: "mem_free"}},
}

drops := [][]*telegraf.Tag{
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cputotal"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu0"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu1"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu2"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_used"}},
{{Key: "cpu", Value: "cputotal"}},
{{Key: "cpu", Value: "cpu0"}},
{{Key: "cpu", Value: "cpu1"}},
{{Key: "cpu", Value: "cpu2"}},
{{Key: "mem", Value: "mem_used"}},
}

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

func TestFilter_TagDrop(t *testing.T) {
filters := []TagFilter{
TagFilter{
{
Name: "cpu",
Filter: []string{"cpu-*"},
},
TagFilter{
{
Name: "mem",
Filter: []string{"mem_free"},
}}
Expand All @@ -302,19 +302,19 @@ func TestFilter_TagDrop(t *testing.T) {
require.NoError(t, f.Compile())

drops := [][]*telegraf.Tag{
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-total"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-0"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-1"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu-2"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_free"}},
{{Key: "cpu", Value: "cpu-total"}},
{{Key: "cpu", Value: "cpu-0"}},
{{Key: "cpu", Value: "cpu-1"}},
{{Key: "cpu", Value: "cpu-2"}},
{{Key: "mem", Value: "mem_free"}},
}

passes := [][]*telegraf.Tag{
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cputotal"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu0"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu1"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "cpu", Value: "cpu2"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "mem", Value: "mem_used"}},
{{Key: "cpu", Value: "cputotal"}},
{{Key: "cpu", Value: "cpu0"}},
{{Key: "cpu", Value: "cpu1"}},
{{Key: "cpu", Value: "cpu2"}},
{{Key: "mem", Value: "mem_used"}},
}

for _, tags := range passes {
Expand Down Expand Up @@ -442,27 +442,27 @@ func TestFilter_FilterFieldPassAndDrop(t *testing.T) {
// see: https://github.com/influxdata/telegraf/issues/2860
func TestFilter_FilterTagsPassAndDrop(t *testing.T) {
inputData := [][]*telegraf.Tag{
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "1"}, &telegraf.Tag{Key: "tag2", Value: "3"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "1"}, &telegraf.Tag{Key: "tag2", Value: "2"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "2"}, &telegraf.Tag{Key: "tag2", Value: "1"}},
[]*telegraf.Tag{&telegraf.Tag{Key: "tag1", Value: "4"}, &telegraf.Tag{Key: "tag2", Value: "1"}},
{{Key: "tag1", Value: "1"}, {Key: "tag2", Value: "3"}},
{{Key: "tag1", Value: "1"}, {Key: "tag2", Value: "2"}},
{{Key: "tag1", Value: "2"}, {Key: "tag2", Value: "1"}},
{{Key: "tag1", Value: "4"}, {Key: "tag2", Value: "1"}},
}

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

filterPass := []TagFilter{
TagFilter{
{
Name: "tag1",
Filter: []string{"1", "4"},
},
}

filterDrop := []TagFilter{
TagFilter{
{
Name: "tag1",
Filter: []string{"4"},
},
TagFilter{
{
Name: "tag2",
Filter: []string{"3"},
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/bcache/bcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func prettyToBytes(v string) uint64 {
}
var factor uint64
factor = 1
prefix := v[len(v)-1 : len(v)]
prefix := v[len(v)-1:]
if factors[prefix] != 0 {
v = v[:len(v)-1]
factor = factors[prefix]
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/ceph/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func flatten(data interface{}) []*metric {

switch val := data.(type) {
case float64:
metrics = []*metric{&metric{make([]string, 0, 1), val}}
metrics = []*metric{{make([]string, 0, 1), val}}
case map[string]interface{}:
metrics = make([]*metric, 0, len(val))
for k, v := range val {
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/ceph/ceph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestGather(t *testing.T) {
}()

findSockets = func(c *Ceph) ([]*socket, error) {
return []*socket{&socket{"osd.1", typeOsd, ""}}, nil
return []*socket{{"osd.1", typeOsd, ""}}, nil
}

perfDump = func(binary string, s *socket) (string, error) {
Expand Down Expand Up @@ -190,17 +190,17 @@ type SockTest struct {
}

var sockTestParams = []*SockTest{
&SockTest{
{
osds: 2,
mons: 2,
},
&SockTest{
{
mons: 1,
},
&SockTest{
{
osds: 1,
},
&SockTest{},
{},
}

var monPerfDump = `
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/cgroup/cgroup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const valuePattern = "[\\d-]+"

var fileFormats = [...]fileFormat{
// VAL\n
fileFormat{
{
name: "Single value",
pattern: "^" + valuePattern + "\n$",
parser: func(measurement string, fields map[string]interface{}, b []byte) {
Expand All @@ -185,7 +185,7 @@ var fileFormats = [...]fileFormat{
// VAL0\n
// VAL1\n
// ...
fileFormat{
{
name: "New line separated values",
pattern: "^(" + valuePattern + "\n){2,}$",
parser: func(measurement string, fields map[string]interface{}, b []byte) {
Expand All @@ -197,7 +197,7 @@ var fileFormats = [...]fileFormat{
},
},
// VAL0 VAL1 ...\n
fileFormat{
{
name: "Space separated values",
pattern: "^(" + valuePattern + " )+\n$",
parser: func(measurement string, fields map[string]interface{}, b []byte) {
Expand All @@ -211,7 +211,7 @@ var fileFormats = [...]fileFormat{
// KEY0 VAL0\n
// KEY1 VAL1\n
// ...
fileFormat{
{
name: "New line separated key-space-value's",
pattern: "^(" + keyPattern + " " + valuePattern + "\n)+$",
parser: func(measurement string, fields map[string]interface{}, b []byte) {
Expand Down
14 changes: 7 additions & 7 deletions plugins/inputs/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (m *mockGatherCloudWatchClient) ListMetrics(params *cloudwatch.ListMetricsI
Namespace: params.Namespace,
MetricName: aws.String("Latency"),
Dimensions: []*cloudwatch.Dimension{
&cloudwatch.Dimension{
{
Name: aws.String("LoadBalancerName"),
Value: aws.String("p-example"),
},
Expand Down Expand Up @@ -100,7 +100,7 @@ func (m *mockSelectMetricsCloudWatchClient) ListMetrics(params *cloudwatch.ListM
Namespace: aws.String("AWS/ELB"),
MetricName: aws.String(m),
Dimensions: []*cloudwatch.Dimension{
&cloudwatch.Dimension{
{
Name: aws.String("LoadBalancerName"),
Value: aws.String(lb),
},
Expand All @@ -112,11 +112,11 @@ func (m *mockSelectMetricsCloudWatchClient) ListMetrics(params *cloudwatch.ListM
Namespace: aws.String("AWS/ELB"),
MetricName: aws.String(m),
Dimensions: []*cloudwatch.Dimension{
&cloudwatch.Dimension{
{
Name: aws.String("LoadBalancerName"),
Value: aws.String(lb),
},
&cloudwatch.Dimension{
{
Name: aws.String("AvailabilityZone"),
Value: aws.String(az),
},
Expand Down Expand Up @@ -148,14 +148,14 @@ func TestSelectMetrics(t *testing.T) {
Period: internalDuration,
RateLimit: 200,
Metrics: []*Metric{
&Metric{
{
MetricNames: []string{"Latency", "RequestCount"},
Dimensions: []*Dimension{
&Dimension{
{
Name: "LoadBalancerName",
Value: "*",
},
&Dimension{
{
Name: "AvailabilityZone",
Value: "*",
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/consul/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

var sampleChecks = []*api.HealthCheck{
&api.HealthCheck{
{
Node: "localhost",
CheckID: "foo.health123",
Name: "foo.health",
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestCPUCountIncrease(t *testing.T) {

mps.On("CPUTimes").Return(
[]cpu.TimesStat{
cpu.TimesStat{
{
CPU: "cpu0",
},
}, nil)
Expand All @@ -173,10 +173,10 @@ func TestCPUCountIncrease(t *testing.T) {

mps2.On("CPUTimes").Return(
[]cpu.TimesStat{
cpu.TimesStat{
{
CPU: "cpu0",
},
cpu.TimesStat{
{
CPU: "cpu1",
},
}, nil)
Expand Down
Loading

0 comments on commit ee05627

Please sign in to comment.