Skip to content

Commit 3e28566

Browse files
committed
all: gofmt code for current go versions
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 30d6825 commit 3e28566

File tree

4 files changed

+100
-96
lines changed

4 files changed

+100
-96
lines changed

README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ fluent-logger-golang
88

99
## How to install
1010

11-
```
12-
go get github.com/fluent/fluent-logger-golang/fluent
11+
```bash
12+
go get github.com/fluent/fluent-logger-golang/fluent@latest
1313
```
1414

1515
## Usage
1616

1717
Install the package with `go get` and use `import` to include it in your project.
1818

19-
```
19+
```go
2020
import "github.com/fluent/fluent-logger-golang/fluent"
2121
```
2222

@@ -26,27 +26,28 @@ import "github.com/fluent/fluent-logger-golang/fluent"
2626
package main
2727

2828
import (
29-
"github.com/fluent/fluent-logger-golang/fluent"
30-
"fmt"
31-
//"time"
29+
"fmt"
30+
// "time"
31+
32+
"github.com/fluent/fluent-logger-golang/fluent"
3233
)
3334

3435
func main() {
35-
logger, err := fluent.New(fluent.Config{})
36-
if err != nil {
37-
fmt.Println(err)
38-
}
39-
defer logger.Close()
40-
tag := "myapp.access"
41-
var data = map[string]string{
42-
"foo": "bar",
43-
"hoge": "hoge",
44-
}
45-
error := logger.Post(tag, data)
46-
// error := logger.PostWithTime(tag, time.Now(), data)
47-
if error != nil {
48-
panic(error)
49-
}
36+
logger, err := fluent.New(fluent.Config{})
37+
if err != nil {
38+
fmt.Println(err)
39+
}
40+
defer logger.Close()
41+
tag := "myapp.access"
42+
data := map[string]string{
43+
"foo": "bar",
44+
"hoge": "hoge",
45+
}
46+
error := logger.Post(tag, data)
47+
// error = logger.PostWithTime(tag, time.Now(), data)
48+
if error != nil {
49+
panic(error)
50+
}
5051
}
5152
```
5253

@@ -181,7 +182,7 @@ were involved. Starting v1.8.0, the logger no longer accepts `Fluent.Post()`
181182
after `Fluent.Close()`, and instead returns a "Logger already closed" error.
182183

183184
## Tests
184-
```
185185

186+
```bash
186187
go test
187188
```

_examples/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"time"
77

8-
"../fluent"
8+
"github.com/fluent/fluent-logger-golang/fluent"
99
)
1010

1111
func main() {
@@ -15,9 +15,10 @@ func main() {
1515
}
1616
defer logger.Close()
1717
tag := "myapp.access"
18-
var data = map[string]string{
18+
data := map[string]string{
1919
"foo": "bar",
20-
"hoge": "hoge"}
20+
"hoge": "hoge",
21+
}
2122
for i := 0; i < 100; i++ {
2223
e := logger.Post(tag, data)
2324
if e != nil {

fluent/fluent.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package fluent
22

33
import (
4+
"bytes"
45
"context"
56
"crypto/tls"
7+
"encoding/base64"
8+
"encoding/binary"
69
"encoding/json"
710
"errors"
811
"fmt"
@@ -15,10 +18,6 @@ import (
1518
"sync"
1619
"time"
1720

18-
"bytes"
19-
"encoding/base64"
20-
"encoding/binary"
21-
2221
"github.com/tinylib/msgp/msgp"
2322
)
2423

@@ -200,27 +199,26 @@ func newWithDialer(config Config, d dialer) (f *Fluent, err error) {
200199
//
201200
// Examples:
202201
//
203-
// // send map[string]
204-
// mapStringData := map[string]string{
205-
// "foo": "bar",
206-
// }
207-
// f.Post("tag_name", mapStringData)
208-
//
209-
// // send message with specified time
210-
// mapStringData := map[string]string{
211-
// "foo": "bar",
212-
// }
213-
// tm := time.Now()
214-
// f.PostWithTime("tag_name", tm, mapStringData)
202+
// // send map[string]
203+
// mapStringData := map[string]string{
204+
// "foo": "bar",
205+
// }
206+
// f.Post("tag_name", mapStringData)
215207
//
216-
// // send struct
217-
// structData := struct {
218-
// Name string `msg:"name"`
219-
// } {
220-
// "john smith",
221-
// }
222-
// f.Post("tag_name", structData)
208+
// // send message with specified time
209+
// mapStringData := map[string]string{
210+
// "foo": "bar",
211+
// }
212+
// tm := time.Now()
213+
// f.PostWithTime("tag_name", tm, mapStringData)
223214
//
215+
// // send struct
216+
// structData := struct {
217+
// Name string `msg:"name"`
218+
// } {
219+
// "john smith",
220+
// }
221+
// f.Post("tag_name", structData)
224222
func (f *Fluent) Post(tag string, message interface{}) error {
225223
timeNow := time.Now()
226224
return f.PostWithTime(tag, timeNow, message)

fluent/fluent_test.go

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ func newTestDialer() *testDialer {
4545
// For instance, to test an async logger that have to dial 4 times before succeeding,
4646
// the test should look like this:
4747
//
48-
// d := newTestDialer() // Create a new stubbed dialer
49-
// cfg := Config{
50-
// Async: true,
51-
// // ...
52-
// }
53-
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
54-
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
48+
// d := newTestDialer() // Create a new stubbed dialer
49+
// cfg := Config{
50+
// Async: true,
51+
// // ...
52+
// }
53+
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
54+
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
5555
//
56-
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
57-
// d.waitForNextDialing(false, false) // 2nd attempt fails too
58-
// d.waitForNextDialing(false, false) // 3rd attempt fails too
59-
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
56+
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
57+
// d.waitForNextDialing(false, false) // 2nd attempt fails too
58+
// d.waitForNextDialing(false, false) // 3rd attempt fails too
59+
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
6060
//
6161
// Note that in the above example, the logger operates in async mode. As such,
6262
// a call to Post, PostWithTime or EncodeAndPostData is needed *before* calling
@@ -67,20 +67,20 @@ func newTestDialer() *testDialer {
6767
// case, you have to put the calls to newWithDialer() and to EncodeAndPostData()
6868
// into their own goroutine. An example:
6969
//
70-
// d := newTestDialer() // Create a new stubbed dialer
71-
// cfg := Config{
72-
// Async: false,
73-
// // ...
74-
// }
75-
// go func() {
76-
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
77-
// f.Close()
78-
// }()
70+
// d := newTestDialer() // Create a new stubbed dialer
71+
// cfg := Config{
72+
// Async: false,
73+
// // ...
74+
// }
75+
// go func() {
76+
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
77+
// f.Close()
78+
// }()
7979
//
80-
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
81-
// d.waitForNextDialing(false, false) // 2nd attempt fails too
82-
// d.waitForNextDialing(false, false) // 3rd attempt fails too
83-
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
80+
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
81+
// d.waitForNextDialing(false, false) // 2nd attempt fails too
82+
// d.waitForNextDialing(false, false) // 3rd attempt fails too
83+
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
8484
//
8585
// Moreover, waitForNextDialing() returns a *Conn which extends net.Conn to provide testing
8686
// facilities. For instance, you can call waitForNextWrite() on these connections, to
@@ -91,24 +91,24 @@ func newTestDialer() *testDialer {
9191
//
9292
// Here's a full example:
9393
//
94-
// d := newTestDialer()
95-
// cfg := Config{Async: true}
94+
// d := newTestDialer()
95+
// cfg := Config{Async: true}
9696
//
97-
// f := newWithDialer(cfg, d)
98-
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
97+
// f := newWithDialer(cfg, d)
98+
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
9999
//
100-
// conn := d.waitForNextDialing(true, false) // Accept the dialing
101-
// conn.waitForNextWrite(false, "") // Discard the 1st attempt to write the message
100+
// conn := d.waitForNextDialing(true, false) // Accept the dialing
101+
// conn.waitForNextWrite(false, "") // Discard the 1st attempt to write the message
102102
//
103-
// conn := d.waitForNextDialing(true, false)
104-
// assertReceived(t, // t is *testing.T
105-
// conn.waitForNextWrite(true, ""),
106-
// "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
103+
// conn := d.waitForNextDialing(true, false)
104+
// assertReceived(t, // t is *testing.T
105+
// conn.waitForNextWrite(true, ""),
106+
// "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
107107
//
108-
// f.EncodeAndPostData("something_else", time.Unix(1482493050, 0), map[string]string{"bar": "baz"})
109-
// assertReceived(t, // t is *testing.T
110-
// conn.waitForNextWrite(true, ""),
111-
// "[\"something_else\",1482493050,{\"bar\":\"baz\"},{}]")
108+
// f.EncodeAndPostData("something_else", time.Unix(1482493050, 0), map[string]string{"bar": "baz"})
109+
// assertReceived(t, // t is *testing.T
110+
// conn.waitForNextWrite(true, ""),
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
@@ -296,7 +296,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
296296

297297
f, err := New(Config{
298298
FluentNetwork: network,
299-
FluentSocketPath: socketFile})
299+
FluentSocketPath: socketFile,
300+
})
300301
if err != nil {
301302
t.Error(err)
302303
return
@@ -309,7 +310,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
309310
network = "unixxxx"
310311
fUnknown, err := New(Config{
311312
FluentNetwork: network,
312-
FluentSocketPath: socketFile})
313+
FluentSocketPath: socketFile,
314+
})
313315
if _, ok := err.(*ErrUnknownNetwork); !ok {
314316
t.Errorf("err type: %T", err)
315317
}
@@ -335,12 +337,12 @@ func Test_MarshalAsMsgpack(t *testing.T) {
335337
f := &Fluent{Config: Config{}}
336338

337339
tag := "tag"
338-
var data = map[string]string{
340+
data := map[string]string{
339341
"foo": "bar",
340-
"hoge": "hoge"}
342+
"hoge": "hoge",
343+
}
341344
tm := time.Unix(1267867237, 0)
342345
result, err := f.EncodeData(tag, tm, data)
343-
344346
if err != nil {
345347
t.Error(err)
346348
}
@@ -368,7 +370,6 @@ func Test_SubSecondPrecision(t *testing.T) {
368370
encodedData, err := fluent.EncodeData("tag", timestamp, map[string]string{
369371
"foo": "bar",
370372
})
371-
372373
// Assert no encoding errors and that the timestamp has been encoded into
373374
// the message as expected.
374375
if err != nil {
@@ -387,12 +388,12 @@ func Test_SubSecondPrecision(t *testing.T) {
387388
func Test_MarshalAsJSON(t *testing.T) {
388389
f := &Fluent{Config: Config{MarshalAsJSON: true}}
389390

390-
var data = map[string]string{
391+
data := map[string]string{
391392
"foo": "bar",
392-
"hoge": "hoge"}
393+
"hoge": "hoge",
394+
}
393395
tm := time.Unix(1267867237, 0)
394396
result, err := f.EncodeData("tag", tm, data)
395-
396397
if err != nil {
397398
t.Error(err)
398399
}
@@ -472,7 +473,10 @@ func TestPostWithTime(t *testing.T) {
472473
_ = f.PostWithTime("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
473474
_ = f.PostWithTime("tag_name", time.Unix(1482493050, 0), map[string]string{"fluentd": "is awesome"})
474475
_ = f.PostWithTime("tag_name", time.Unix(1634263200, 0),
475-
struct {Welcome string `msg:"welcome"`; cannot string}{"to use", "see me"})
476+
struct {
477+
Welcome string `msg:"welcome"`
478+
cannot string
479+
}{"to use", "see me"})
476480
}()
477481

478482
conn := d.waitForNextDialing(true, false)

0 commit comments

Comments
 (0)