Skip to content

Commit 08984d0

Browse files
authored
Merge pull request #56 from NETWAYS/refactor-strings
Refactor to use strings.Builder
2 parents 25e5d49 + c51ecc3 commit 08984d0

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

.golangci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ linters:
1111
- funlen
1212
- dogsled
1313
- dupl
14-
# - lll
1514
- whitespace
1615
- wsl
1716
- exportloopref
@@ -25,8 +24,8 @@ linters:
2524
- sqlclosecheck
2625
- structcheck
2726
- unparam
27+
- musttag
2828
presets:
2929
- bugs
3030
- unused
31-
# - style
3231
fast: false

cmd/health.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111
"net/http"
1212
"net/url"
13+
"strings"
1314
)
1415

1516
// To store the CLI parameters
@@ -142,7 +143,6 @@ var healthCmd = &cobra.Command{
142143
Run: func(cmd *cobra.Command, args []string) {
143144
var (
144145
output string
145-
summary string
146146
rc int
147147
stat logstash.Stat
148148
thresholds HealthThreshold
@@ -247,11 +247,12 @@ var healthCmd = &cobra.Command{
247247
}
248248

249249
// Generate summary for subchecks
250-
summary += fmt.Sprintf("\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent)
251-
summary += fmt.Sprintf("\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent)
252-
summary += fmt.Sprintf("\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent)
250+
var summary strings.Builder
251+
summary.WriteString(fmt.Sprintf("\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent))
252+
summary.WriteString(fmt.Sprintf("\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent))
253+
summary.WriteString(fmt.Sprintf("\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent))
253254

254-
check.ExitRaw(rc, output, summary, "|", perfList.String())
255+
check.ExitRaw(rc, output, summary.String(), "|", perfList.String())
255256
},
256257
}
257258

cmd/pipeline.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111
"net/http"
1212
"net/url"
13+
"strings"
1314
)
1415

1516
// To store the CLI parameters
@@ -64,7 +65,6 @@ var pipelineCmd = &cobra.Command{
6465
Run: func(cmd *cobra.Command, args []string) {
6566
var (
6667
output string
67-
summary string
6868
rc int
6969
pp logstash.Pipeline
7070
thresholds PipelineThreshold
@@ -102,19 +102,21 @@ var pipelineCmd = &cobra.Command{
102102
states := make([]int, 0, len(pp.Pipelines))
103103

104104
// Check status for each pipeline
105+
var summary strings.Builder
106+
105107
for name, pipe := range pp.Pipelines {
106108
inflightEvents := pipe.Events.In - pipe.Events.Out
107109

108-
summary += "\n \\_"
110+
summary.WriteString("\n \\_")
109111
if thresholds.inflightEventsCrit.DoesViolate(float64(inflightEvents)) {
110112
states = append(states, check.Critical)
111-
summary += fmt.Sprintf("[CRITICAL] inflight_events_%s:%d;", name, inflightEvents)
113+
summary.WriteString(fmt.Sprintf("[CRITICAL] inflight_events_%s:%d;", name, inflightEvents))
112114
} else if thresholds.inflightEventsWarn.DoesViolate(float64(inflightEvents)) {
113115
states = append(states, check.Warning)
114-
summary += fmt.Sprintf("[WARNING] inflight_events_%s:%d;", name, inflightEvents)
116+
summary.WriteString(fmt.Sprintf("[WARNING] inflight_events_%s:%d;", name, inflightEvents))
115117
} else {
116118
states = append(states, check.OK)
117-
summary += fmt.Sprintf("[OK] inflight_events_%s:%d;", name, inflightEvents)
119+
summary.WriteString(fmt.Sprintf("[OK] inflight_events_%s:%d;", name, inflightEvents))
118120
}
119121

120122
// Generate perfdata for each event
@@ -155,7 +157,7 @@ var pipelineCmd = &cobra.Command{
155157
output = "Inflight events status unknown"
156158
}
157159

158-
check.ExitRaw(rc, output, summary, "|", perfList.String())
160+
check.ExitRaw(rc, output, summary.String(), "|", perfList.String())
159161
},
160162
}
161163

0 commit comments

Comments
 (0)