refactor(pkg): clean up perfdata to string conversion
This commit is contained in:
parent
47b342b317
commit
cf88d63bc2
1 changed files with 9 additions and 8 deletions
|
@ -3,7 +3,6 @@
|
|||
package perfdata // import nocternity.net/gomonop/pkg/perfdata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -70,26 +69,28 @@ func (d *PerfData) String() string {
|
|||
var strBuilder strings.Builder
|
||||
needsQuotes := strings.ContainsAny(d.Label, " '=\"")
|
||||
if needsQuotes {
|
||||
strBuilder.WriteString("'")
|
||||
strBuilder.WriteRune('\'')
|
||||
}
|
||||
strBuilder.WriteString(strings.ReplaceAll(d.Label, "'", "''"))
|
||||
if needsQuotes {
|
||||
strBuilder.WriteString("'")
|
||||
strBuilder.WriteRune('\'')
|
||||
}
|
||||
strBuilder.WriteString("=")
|
||||
strBuilder.WriteString(fmt.Sprintf("%s%s;", d.value, d.units.String()))
|
||||
strBuilder.WriteRune('=')
|
||||
strBuilder.WriteString(d.value)
|
||||
strBuilder.WriteString(d.units.String())
|
||||
strBuilder.WriteRune(';')
|
||||
if d.bits&PDatWarn != 0 {
|
||||
strBuilder.WriteString(d.warn.String())
|
||||
}
|
||||
strBuilder.WriteString(";")
|
||||
strBuilder.WriteRune(';')
|
||||
if d.bits&PDatCrit != 0 {
|
||||
strBuilder.WriteString(d.crit.String())
|
||||
}
|
||||
strBuilder.WriteString(";")
|
||||
strBuilder.WriteRune(';')
|
||||
if d.bits&PDatMin != 0 {
|
||||
strBuilder.WriteString(d.min)
|
||||
}
|
||||
strBuilder.WriteString(";")
|
||||
strBuilder.WriteRune(';')
|
||||
if d.bits&PDatMax != 0 {
|
||||
strBuilder.WriteString(d.max)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue