edgexfoundry/go-mod-core-contracts

Improve the string concatenate logic in ToLineProtocol function

Closed this issue ยท 0 comments

๐Ÿš€ Feature Request

Relevant Package [REQUIRED]

This feature request is for all

Description [REQUIRED]

The current string concatenate logic could be improved by string builder
https://pkg.go.dev/strings#Builder

Using lots of += in string is not a good practice.

for _, field := range m.Fields {
// Fields section doesn't have a leading comma per syntax above so need to skip the comma on the first field
if isFirst {
isFirst = false
} else {
fields += ","
}
fields += fmt.Sprintf("%s=%s", field.Name, formatLineProtocolValue(field.Value))
}
// Tags section does have a leading comma per syntax above
tags := ""
for _, tag := range m.Tags {
tags += fmt.Sprintf(",%s=%s", tag.Name, tag.Value)
}