refactor: fix many linter warnings
This commit is contained in:
parent
43e4f2a6f0
commit
68b88bc766
7 changed files with 191 additions and 163 deletions
pkg/plugin
|
@ -58,17 +58,22 @@ func (p *Plugin) SetState(status Status, message string) {
|
|||
}
|
||||
|
||||
// AddLine adds the specified string to the extra output text buffer.
|
||||
func (p *Plugin) AddLine(format string, data ...interface{}) {
|
||||
func (p *Plugin) AddLine(line string) {
|
||||
if p.extraText == nil {
|
||||
p.extraText = list.New()
|
||||
}
|
||||
p.extraText.PushBack(fmt.Sprintf(format, data...))
|
||||
p.extraText.PushBack(line)
|
||||
}
|
||||
|
||||
// AddLinef formats the input and adds it to the text buffer.
|
||||
func (p *Plugin) AddLinef(format string, data ...interface{}) {
|
||||
p.AddLine(fmt.Sprintf(format, data...))
|
||||
}
|
||||
|
||||
// AddLines add the specified `lines` to the output text.
|
||||
func (p *Plugin) AddLines(lines []string) {
|
||||
for _, line := range lines {
|
||||
p.AddLine("%s", line)
|
||||
p.AddLine(line)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +83,7 @@ func (p *Plugin) AddLines(lines []string) {
|
|||
func (p *Plugin) AddPerfData(pd *perfdata.PerfData) {
|
||||
_, exists := p.perfData[pd.Label]
|
||||
if exists {
|
||||
panic(fmt.Sprintf("duplicate performance data %s", pd.Label))
|
||||
panic("duplicate performance data " + pd.Label)
|
||||
}
|
||||
p.perfData[pd.Label] = pd
|
||||
}
|
||||
|
@ -87,30 +92,31 @@ func (p *Plugin) AddPerfData(pd *perfdata.PerfData) {
|
|||
// and performance data, before exiting with the code corresponding to the
|
||||
// status.
|
||||
func (p *Plugin) Done() {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(p.name)
|
||||
sb.WriteString(" ")
|
||||
sb.WriteString(p.status.String())
|
||||
sb.WriteString(": ")
|
||||
sb.WriteString(p.message)
|
||||
var strBuilder strings.Builder
|
||||
strBuilder.WriteString(p.name)
|
||||
strBuilder.WriteString(" ")
|
||||
strBuilder.WriteString(p.status.String())
|
||||
strBuilder.WriteString(": ")
|
||||
strBuilder.WriteString(p.message)
|
||||
if len(p.perfData) > 0 {
|
||||
sb.WriteString(" | ")
|
||||
strBuilder.WriteString(" | ")
|
||||
needSep := false
|
||||
for k := range p.perfData {
|
||||
for _, data := range p.perfData {
|
||||
if needSep {
|
||||
sb.WriteString(", ")
|
||||
strBuilder.WriteString(", ")
|
||||
} else {
|
||||
needSep = true
|
||||
}
|
||||
sb.WriteString(p.perfData[k].String())
|
||||
strBuilder.WriteString(data.String())
|
||||
}
|
||||
}
|
||||
if p.extraText != nil {
|
||||
for em := p.extraText.Front(); em != nil; em = em.Next() {
|
||||
sb.WriteString("\n")
|
||||
sb.WriteString(em.Value.(string))
|
||||
strBuilder.WriteString("\n")
|
||||
//nolint:forcetypeassert // we want to panic if this isn't a string
|
||||
strBuilder.WriteString(em.Value.(string))
|
||||
}
|
||||
}
|
||||
fmt.Println(sb.String())
|
||||
fmt.Println(strBuilder.String())
|
||||
os.Exit(int(p.status))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue