From fc18f4a036664fe7e7eafbf87e3d839642c26cc2 Mon Sep 17 00:00:00 2001 From: Madhurjya Roy Date: Thu, 15 Aug 2024 18:24:51 +0530 Subject: [PATCH] fix: fix tags --- cmd/dogstatsd-local/main.go | 5 ++++- internal/format/pretty/pretty.go | 6 +----- internal/messages/messages.go | 3 +++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/dogstatsd-local/main.go b/cmd/dogstatsd-local/main.go index 0e063b4..bec6cd0 100644 --- a/cmd/dogstatsd-local/main.go +++ b/cmd/dogstatsd-local/main.go @@ -32,7 +32,10 @@ func main() { debug := flag.Bool("debug", false, "Enable debug mode") flag.Parse() - extraTags := strings.Split(*rawTags, ",") + var extraTags []string + if *rawTags != "" { + extraTags = strings.Split(*rawTags, ",") + } logger := getLogger(*debug) var formatHandler format.Handler diff --git a/internal/format/pretty/pretty.go b/internal/format/pretty/pretty.go index 7bd4de3..187e429 100644 --- a/internal/format/pretty/pretty.go +++ b/internal/format/pretty/pretty.go @@ -119,9 +119,5 @@ func (h *Handler) StyledTags(metric messages.DogStatsDMetric, extraTags []string style := lipgloss.NewStyle(). Foreground(h.Theme.Overlay0()). Italic(true) - var tags []string - for _, tag := range append(extraTags, metric.Tags...) { - tags = append(tags, strings.TrimSpace(tag)) - } - return style.SetString(tags...).Render() + return style.SetString(append(extraTags, metric.Tags...)...).Render() } diff --git a/internal/messages/messages.go b/internal/messages/messages.go index 0b4f395..ab44c2d 100644 --- a/internal/messages/messages.go +++ b/internal/messages/messages.go @@ -171,6 +171,9 @@ func parseDogStatsDMetricMessage(buf []byte) (DogStatsDMessage, error) { if strings.HasPrefix(piece, "#") { tags := strings.Split(piece[1:], ",") + for i, _ := range tags { + tags[i] = strings.TrimSpace(tags[i]) + } metric.Tags = append(metric.Tags, tags...) continue }