-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
54 lines (47 loc) · 860 Bytes
/
example_test.go
File metadata and controls
54 lines (47 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package jsonseq
import (
"fmt"
"io"
"os"
"strings"
)
func ExampleWriteRecord() {
_ = WriteRecord(os.Stdout, []byte(`{"id":1}`))
_ = WriteRecord(os.Stdout, []byte(`{"id":2}`))
_ = WriteRecord(os.Stdout, []byte(`{"id":3}`))
// Output:
// {"id":1}
// {"id":2}
// {"id":3}
//
}
func ExampleNewEncoder() {
encoder := NewEncoder(os.Stdout)
_ = encoder.Encode("Test")
_ = encoder.Encode(123.456)
_ = encoder.Encode(struct{ Id int }{Id: 1})
// Output:
// "Test"
// 123.456
// {"Id":1}
//
}
func ExampleDecoder_Decode() {
d := NewDecoder(strings.NewReader(`{"id":1} 12341234 true discarded junk`))
for {
var i interface{}
if err := d.Decode(&i); err != nil {
if err == io.EOF {
break
}
fmt.Println(err)
} else {
fmt.Println(i)
}
}
// Output:
// map[id:1]
// invalid record: "1234"
// 1234
// true
}