Skip to content

Commit 7f04159

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 e3180c4 commit 7f04159

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
@@ -103,12 +103,12 @@ func newTestDialer() *testDialer {
103103
// conn := d.waitForNextDialing(true, false)
104104
// assertReceived(t, // t is *testing.T
105105
// conn.waitForNextWrite(true, ""),
106-
// "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
106+
// `["tag_name",1482493046,{"foo":"bar"},{}]`)
107107
//
108108
// f.EncodeAndPostData("something_else", time.Unix(1482493050, 0), map[string]string{"bar": "baz"})
109109
// assertReceived(t, // t is *testing.T
110110
// conn.waitForNextWrite(true, ""),
111-
// "[\"something_else\",1482493050,{\"bar\":\"baz\"},{}]")
111+
// `["something_else",1482493050,{"bar":"baz"},{}]`)
112112
//
113113
// In this example, the 1st connection dialing succeeds but the 1st attempt to write the
114114
// message is discarded. As the logger discards the connection whenever a message
@@ -118,7 +118,7 @@ func newTestDialer() *testDialer {
118118
// using assertReceived() to make sure the logger encodes the messages properly.
119119
//
120120
// Again, the example above is using async mode thus, calls to f and conn are running in
121-
// the same goroutine. However in sync mode, all calls to f.EncodeAndPostData() as well
121+
// the same goroutine. However, in sync mode, all calls to f.EncodeAndPostData() as well
122122
// as the logger initialization shall be placed in a separate goroutine or the code
123123
// allowing the dialing and writing attempts (eg. waitForNextDialing() & waitForNextWrite())
124124
// would never be reached.
@@ -482,14 +482,14 @@ func TestPostWithTime(t *testing.T) {
482482
conn := d.waitForNextDialing(true, false)
483483
assertReceived(t,
484484
conn.waitForNextWrite(true, ""),
485-
"[\"acme.tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
485+
`["acme.tag_name",1482493046,{"foo":"bar"},{}]`)
486486

487487
assertReceived(t,
488488
conn.waitForNextWrite(true, ""),
489-
"[\"acme.tag_name\",1482493050,{\"fluentd\":\"is awesome\"},{}]")
489+
`["acme.tag_name",1482493050,{"fluentd":"is awesome"},{}]`)
490490
assertReceived(t,
491491
conn.waitForNextWrite(true, ""),
492-
"[\"acme.tag_name\",1634263200,{\"welcome\":\"to use\"},{}]")
492+
`["acme.tag_name",1634263200,{"welcome":"to use"},{}]`)
493493
})
494494
}
495495
}
@@ -533,7 +533,7 @@ func TestReconnectAndResendAfterTransientFailure(t *testing.T) {
533533
conn := d.waitForNextDialing(true, false)
534534
assertReceived(t,
535535
conn.waitForNextWrite(true, ""),
536-
"[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
536+
`["tag_name",1482493046,{"foo":"bar"},{}]`)
537537

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

0 commit comments

Comments
 (0)