Skip to content

Commit 58f4c93

Browse files
committed
use string-literals to prevent having to escape quotes
This makes the code and examples slightly more readable. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 5d51b81 commit 58f4c93

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

fluent/fluent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (chunk *MessageChunk) MarshalJSON() ([]byte, error) {
322322
if err != nil {
323323
return nil, err
324324
}
325-
return []byte(fmt.Sprintf("[\"%s\",%d,%s,%s]", chunk.message.Tag,
325+
return []byte(fmt.Sprintf(`["%s",%d,%s,%s]`, chunk.message.Tag,
326326
chunk.message.Time, data, option)), err
327327
}
328328

fluent/fluent_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ func newTestDialer() *testDialer {
105105
// conn := d.waitForNextDialing(true, false)
106106
// assertReceived(t, // t is *testing.T
107107
// conn.waitForNextWrite(true, ""),
108-
// "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
108+
// `["tag_name",1482493046,{"foo":"bar"},{}]`)
109109
//
110110
// f.EncodeAndPostData("something_else", time.Unix(1482493050, 0), map[string]string{"bar": "baz"})
111111
// assertReceived(t, // t is *testing.T
112112
// conn.waitForNextWrite(true, ""),
113-
// "[\"something_else\",1482493050,{\"bar\":\"baz\"},{}]")
113+
// `["something_else",1482493050,{"bar":"baz"},{}]`)
114114
//
115115
// In this example, the 1st connection dialing succeeds but the 1st attempt to write the
116116
// message is discarded. As the logger discards the connection whenever a message
@@ -120,7 +120,7 @@ func newTestDialer() *testDialer {
120120
// using assertReceived() to make sure the logger encodes the messages properly.
121121
//
122122
// Again, the example above is using async mode thus, calls to f and conn are running in
123-
// the same goroutine. However in sync mode, all calls to f.EncodeAndPostData() as well
123+
// the same goroutine. However, in sync mode, all calls to f.EncodeAndPostData() as well
124124
// as the logger initialization shall be placed in a separate goroutine or the code
125125
// allowing the dialing and writing attempts (eg. waitForNextDialing() & waitForNextWrite())
126126
// would never be reached.
@@ -495,14 +495,14 @@ func TestPostWithTime(t *testing.T) {
495495
conn := d.waitForNextDialing(true, false)
496496
assertReceived(t,
497497
conn.waitForNextWrite(true, ""),
498-
"[\"acme.tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
498+
`["acme.tag_name",1482493046,{"foo":"bar"},{}]`)
499499

500500
assertReceived(t,
501501
conn.waitForNextWrite(true, ""),
502-
"[\"acme.tag_name\",1482493050,{\"fluentd\":\"is awesome\"},{}]")
502+
`["acme.tag_name",1482493050,{"fluentd":"is awesome"},{}]`)
503503
assertReceived(t,
504504
conn.waitForNextWrite(true, ""),
505-
"[\"acme.tag_name\",1634263200,{\"welcome\":\"to use\"},{}]")
505+
`["acme.tag_name",1634263200,{"welcome":"to use"},{}]`)
506506
})
507507
}
508508
}
@@ -546,7 +546,7 @@ func TestReconnectAndResendAfterTransientFailure(t *testing.T) {
546546
conn := d.waitForNextDialing(true, false)
547547
assertReceived(t,
548548
conn.waitForNextWrite(true, ""),
549-
"[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
549+
`["tag_name",1482493046,{"foo":"bar"},{}]`)
550550

551551
// The next write will fail and the next connection dialing will be dropped
552552
// to test if the logger is reconnecting as expected.
@@ -557,7 +557,7 @@ func TestReconnectAndResendAfterTransientFailure(t *testing.T) {
557557
conn = d.waitForNextDialing(true, false)
558558
assertReceived(t,
559559
conn.waitForNextWrite(true, ""),
560-
"[\"tag_name\",1482493050,{\"fluentd\":\"is awesome\"},{}]")
560+
`["tag_name",1482493050,{"fluentd":"is awesome"},{}]`)
561561
})
562562
}
563563
}

0 commit comments

Comments
 (0)