Skip to content

Commit

Permalink
chore: replace custom replacer with strings.Replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
karel-rehor committed Oct 17, 2024
1 parent d0fc985 commit 0d31a4b
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions influxdb3/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,10 @@ func (p *Point) MarshalBinaryWithDefaultTags(precision lineprotocol.Precision, d
// N.B. Some customers have requested support for newline and tab chars in tag values (EAR 5476)
// Though this is outside the lineprotocol specification, it was supported in
// previous GO client versions.
tagEscapes := map[string]string{
"\n": "\\n",
"\t": "\\t",
}

replacer := func(reps map[string]string, s string) string {
result := s
for key, val := range reps {
result = strings.ReplaceAll(result, key, val)
}
return result
}
replacer := strings.NewReplacer(
"\n", "\\n",
"\t", "\\t",
)

// sort Tags
tagKeys := make([]string, 0, len(p.Values.Tags)+len(defaultTags))
Expand All @@ -287,9 +279,9 @@ func (p *Point) MarshalBinaryWithDefaultTags(precision lineprotocol.Precision, d

// N.B. Some customers have requested support for newline and tab chars in tag values (EAR 5476)
if value, ok := p.Values.Tags[tagKey]; ok {
enc.AddTag(tagKey, replacer(tagEscapes, value))
enc.AddTag(tagKey, replacer.Replace(value))
} else {
enc.AddTag(tagKey, replacer(tagEscapes, defaultTags[tagKey]))
enc.AddTag(tagKey, replacer.Replace(defaultTags[tagKey]))
}
}

Expand Down

0 comments on commit 0d31a4b

Please sign in to comment.