From 00d3a3272f03c78d2910bb4f311b13b32d073fc6 Mon Sep 17 00:00:00 2001 From: Alex Normand Date: Tue, 29 Mar 2022 18:39:45 -0700 Subject: [PATCH] Add godoc and move main function to top --- ddtrace/tracer/sqlcomment.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ddtrace/tracer/sqlcomment.go b/ddtrace/tracer/sqlcomment.go index 0dab6ccf02..f6ffbdef5d 100644 --- a/ddtrace/tracer/sqlcomment.go +++ b/ddtrace/tracer/sqlcomment.go @@ -7,10 +7,19 @@ import ( "strings" ) +// SQLCommentCarrier holds tags to be serialized as a SQL Comment type SQLCommentCarrier struct { tags map[string]string } +// Set implements TextMapWriter. +func (c *SQLCommentCarrier) Set(key, val string) { + if c.tags == nil { + c.tags = make(map[string]string) + } + c.tags[key] = val +} + func commentWithTags(tags map[string]string) (comment string) { if len(tags) == 0 { return "" @@ -26,14 +35,8 @@ func commentWithTags(tags map[string]string) (comment string) { return fmt.Sprintf("/* %s */", comment) } -// Set implements TextMapWriter. -func (c *SQLCommentCarrier) Set(key, val string) { - if c.tags == nil { - c.tags = make(map[string]string) - } - c.tags[key] = val -} - +// CommentedQuery returns the given query with the tags from the SQLCommentCarrier applied to it as a +// prepended SQL comment func (c *SQLCommentCarrier) CommentedQuery(query string) (commented string) { comment := commentWithTags(c.tags)