From 0d31a4bdab316d9718970338e50d7e05c83dbd94 Mon Sep 17 00:00:00 2001 From: karel rehor Date: Thu, 17 Oct 2024 14:02:37 +0200 Subject: [PATCH] chore: replace custom replacer with strings.Replacer --- influxdb3/point.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/influxdb3/point.go b/influxdb3/point.go index e026e1d..ce3e9b1 100644 --- a/influxdb3/point.go +++ b/influxdb3/point.go @@ -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)) @@ -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])) } }