Skip to content

Commit d6ff223

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

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
@@ -44,18 +44,18 @@ func newTestDialer() *testDialer {
4444
// For instance, to test an async logger that have to dial 4 times before succeeding,
4545
// the test should look like this:
4646
//
47-
// d := newTestDialer() // Create a new stubbed dialer
48-
// cfg := Config{
49-
// Async: true,
50-
// // ...
51-
// }
52-
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
53-
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
47+
// d := newTestDialer() // Create a new stubbed dialer
48+
// cfg := Config{
49+
// Async: true,
50+
// // ...
51+
// }
52+
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
53+
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
5454
//
55-
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
56-
// d.waitForNextDialing(false, false) // 2nd attempt fails too
57-
// d.waitForNextDialing(false, false) // 3rd attempt fails too
58-
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
55+
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
56+
// d.waitForNextDialing(false, false) // 2nd attempt fails too
57+
// d.waitForNextDialing(false, false) // 3rd attempt fails too
58+
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
5959
//
6060
// Note that in the above example, the logger operates in async mode. As such,
6161
// a call to Post, PostWithTime or EncodeAndPostData is needed *before* calling
@@ -66,20 +66,20 @@ func newTestDialer() *testDialer {
6666
// case, you have to put the calls to newWithDialer() and to EncodeAndPostData()
6767
// into their own goroutine. An example:
6868
//
69-
// d := newTestDialer() // Create a new stubbed dialer
70-
// cfg := Config{
71-
// Async: false,
72-
// // ...
73-
// }
74-
// go func() {
75-
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
76-
// f.Close()
77-
// }()
69+
// d := newTestDialer() // Create a new stubbed dialer
70+
// cfg := Config{
71+
// Async: false,
72+
// // ...
73+
// }
74+
// go func() {
75+
// f := newWithDialer(cfg, d) // Create a fluent logger using the stubbed dialer
76+
// f.Close()
77+
// }()
7878
//
79-
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
80-
// d.waitForNextDialing(false, false) // 2nd attempt fails too
81-
// d.waitForNextDialing(false, false) // 3rd attempt fails too
82-
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
79+
// d.waitForNextDialing(false, false) // 1st dialing attempt fails
80+
// d.waitForNextDialing(false, false) // 2nd attempt fails too
81+
// d.waitForNextDialing(false, false) // 3rd attempt fails too
82+
// d.waitForNextDialing(true, false) // Finally the 4th attempt succeeds
8383
//
8484
// Moreover, waitForNextDialing() returns a *Conn which extends net.Conn to provide testing
8585
// facilities. For instance, you can call waitForNextWrite() on these connections, to
@@ -90,24 +90,24 @@ func newTestDialer() *testDialer {
9090
//
9191
// Here's a full example:
9292
//
93-
// d := newTestDialer()
94-
// cfg := Config{Async: true}
93+
// d := newTestDialer()
94+
// cfg := Config{Async: true}
9595
//
96-
// f := newWithDialer(cfg, d)
97-
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
96+
// f := newWithDialer(cfg, d)
97+
// f.EncodeAndPostData("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
9898
//
99-
// conn := d.waitForNextDialing(true, false) // Accept the dialing
100-
// conn.waitForNextWrite(false, "") // Discard the 1st attempt to write the message
99+
// conn := d.waitForNextDialing(true, false) // Accept the dialing
100+
// conn.waitForNextWrite(false, "") // Discard the 1st attempt to write the message
101101
//
102-
// conn := d.waitForNextDialing(true, false)
103-
// assertReceived(t, // t is *testing.T
104-
// conn.waitForNextWrite(true, ""),
105-
// "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
102+
// conn := d.waitForNextDialing(true, false)
103+
// assertReceived(t, // t is *testing.T
104+
// conn.waitForNextWrite(true, ""),
105+
// "[\"tag_name\",1482493046,{\"foo\":\"bar\"},{}]")
106106
//
107-
// f.EncodeAndPostData("something_else", time.Unix(1482493050, 0), map[string]string{"bar": "baz"})
108-
// assertReceived(t, // t is *testing.T
109-
// conn.waitForNextWrite(true, ""),
110-
// "[\"something_else\",1482493050,{\"bar\":\"baz\"},{}]")
107+
// f.EncodeAndPostData("something_else", time.Unix(1482493050, 0), map[string]string{"bar": "baz"})
108+
// assertReceived(t, // t is *testing.T
109+
// conn.waitForNextWrite(true, ""),
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
@@ -303,7 +303,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
303303

304304
f, err := New(Config{
305305
FluentNetwork: network,
306-
FluentSocketPath: socketFile})
306+
FluentSocketPath: socketFile,
307+
})
307308
if err != nil {
308309
t.Error(err)
309310
return
@@ -316,7 +317,8 @@ func Test_New_itShouldUseUnixDomainSocketIfUnixSocketSpecified(t *testing.T) {
316317
network = "unixxxx"
317318
fUnknown, err := New(Config{
318319
FluentNetwork: network,
319-
FluentSocketPath: socketFile})
320+
FluentSocketPath: socketFile,
321+
})
320322
if _, ok := err.(*ErrUnknownNetwork); !ok {
321323
t.Errorf("err type: %T", err)
322324
}
@@ -342,12 +344,12 @@ func Test_MarshalAsMsgpack(t *testing.T) {
342344
f := &Fluent{Config: Config{}}
343345

344346
tag := "tag"
345-
var data = map[string]string{
347+
data := map[string]string{
346348
"foo": "bar",
347-
"hoge": "hoge"}
349+
"hoge": "hoge",
350+
}
348351
tm := time.Unix(1267867237, 0)
349352
result, err := f.EncodeData(tag, tm, data)
350-
351353
if err != nil {
352354
t.Error(err)
353355
}
@@ -375,7 +377,6 @@ func Test_SubSecondPrecision(t *testing.T) {
375377
encodedData, err := fluent.EncodeData("tag", timestamp, map[string]string{
376378
"foo": "bar",
377379
})
378-
379380
// Assert no encoding errors and that the timestamp has been encoded into
380381
// the message as expected.
381382
if err != nil {
@@ -394,12 +395,12 @@ func Test_SubSecondPrecision(t *testing.T) {
394395
func Test_MarshalAsJSON(t *testing.T) {
395396
f := &Fluent{Config: Config{MarshalAsJSON: true}}
396397

397-
var data = map[string]string{
398+
data := map[string]string{
398399
"foo": "bar",
399-
"hoge": "hoge"}
400+
"hoge": "hoge",
401+
}
400402
tm := time.Unix(1267867237, 0)
401403
result, err := f.EncodeData("tag", tm, data)
402-
403404
if err != nil {
404405
t.Error(err)
405406
}
@@ -477,7 +478,10 @@ func TestPostWithTime(t *testing.T) {
477478
_ = f.PostWithTime("tag_name", time.Unix(1482493046, 0), map[string]string{"foo": "bar"})
478479
_ = f.PostWithTime("tag_name", time.Unix(1482493050, 0), map[string]string{"fluentd": "is awesome"})
479480
_ = f.PostWithTime("tag_name", time.Unix(1634263200, 0),
480-
struct {Welcome string `msg:"welcome"`; cannot string}{"to use", "see me"})
481+
struct {
482+
Welcome string `msg:"welcome"`
483+
cannot string
484+
}{"to use", "see me"})
481485
}()
482486

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

0 commit comments

Comments
 (0)