Skip to content

Commit 82c5cdd

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 <[email protected]>
1 parent 81384af commit 82c5cdd

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
@@ -315,7 +315,7 @@ func (chunk *MessageChunk) MarshalJSON() ([]byte, error) {
315315
if err != nil {
316316
return nil, err
317317
}
318-
return []byte(fmt.Sprintf("[\"%s\",%d,%s,%s]", chunk.message.Tag,
318+
return []byte(fmt.Sprintf(`["%s",%d,%s,%s]`, chunk.message.Tag,
319319
chunk.message.Time, data, option)), err
320320
}
321321

fluent/fluent_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ func newTestDialer() *testDialer {
102102
// conn := d.waitForNextDialing(true, false)
103103
// assertReceived(t, // t is *testing.T
104104
// conn.waitForNextWrite(true, ""),
105-
// "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
105+
// `["tag_name",1482493046,{"foo":"bar"},{}]`)
106106
//
107107
// f.EncodeAndPostData("something_else", time.Unix(1482493050, 0), map[string]string{"bar": "baz"})
108108
// assertReceived(t, // t is *testing.T
109109
// conn.waitForNextWrite(true, ""),
110-
// "[\"something_else\",1482493050,{\"bar\":\"baz\"},{}]")
110+
// `["something_else",1482493050,{"bar":"baz"},{}]`)
111111
//
112112
// In this example, the 1st connection dialing succeeds but the 1st attempt to write the
113113
// message is discarded. As the logger discards the connection whenever a message
@@ -117,7 +117,7 @@ func newTestDialer() *testDialer {
117117
// using assertReceived() to make sure the logger encodes the messages properly.
118118
//
119119
// Again, the example above is using async mode thus, calls to f and conn are running in
120-
// the same goroutine. However in sync mode, all calls to f.EncodeAndPostData() as well
120+
// the same goroutine. However, in sync mode, all calls to f.EncodeAndPostData() as well
121121
// as the logger initialization shall be placed in a separate goroutine or the code
122122
// allowing the dialing and writing attempts (eg. waitForNextDialing() & waitForNextWrite())
123123
// would never be reached.
@@ -487,14 +487,14 @@ func TestPostWithTime(t *testing.T) {
487487
conn := d.waitForNextDialing(true, false)
488488
assertReceived(t,
489489
conn.waitForNextWrite(true, ""),
490-
"[\"acme.tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
490+
`["acme.tag_name",1482493046,{"foo":"bar"},{}]`)
491491

492492
assertReceived(t,
493493
conn.waitForNextWrite(true, ""),
494-
"[\"acme.tag_name\",1482493050,{\"fluentd\":\"is awesome\"},{}]")
494+
`["acme.tag_name",1482493050,{"fluentd":"is awesome"},{}]`)
495495
assertReceived(t,
496496
conn.waitForNextWrite(true, ""),
497-
"[\"acme.tag_name\",1634263200,{\"welcome\":\"to use\"},{}]")
497+
`["acme.tag_name",1634263200,{"welcome":"to use"},{}]`)
498498
})
499499
}
500500
}
@@ -538,7 +538,7 @@ func TestReconnectAndResendAfterTransientFailure(t *testing.T) {
538538
conn := d.waitForNextDialing(true, false)
539539
assertReceived(t,
540540
conn.waitForNextWrite(true, ""),
541-
"[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
541+
`["tag_name",1482493046,{"foo":"bar"},{}]`)
542542

543543
// The next write will fail and the next connection dialing will be dropped
544544
// to test if the logger is reconnecting as expected.
@@ -549,7 +549,7 @@ func TestReconnectAndResendAfterTransientFailure(t *testing.T) {
549549
conn = d.waitForNextDialing(true, false)
550550
assertReceived(t,
551551
conn.waitForNextWrite(true, ""),
552-
"[\"tag_name\",1482493050,{\"fluentd\":\"is awesome\"},{}]")
552+
`["tag_name",1482493050,{"fluentd":"is awesome"},{}]`)
553553
})
554554
}
555555
}

0 commit comments

Comments
 (0)