Skip to content

Commit dd3bc12

Browse files
committed
update README
1 parent 0f58d9e commit dd3bc12

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,14 @@ func main() {
299299
with Encode:
300300
```go
301301
func main() {
302-
u := &user{1, "gojay", "[email protected]"}
303-
b := strings.Builder{}
304-
if err := gojay.NewEncoder(&b); err != nil {
305-
log.Fatal(err)
306-
}
307-
fmt.Println(b.String()) // {"id":1,"name":"gojay","email":"[email protected]"}
302+
func main() {
303+
u := &user{1, "gojay", "[email protected]"}
304+
b := strings.Builder{}
305+
enc := gojay.NewEncoder(&b)
306+
if err := enc.Encode(u); err != nil {
307+
log.Fatal(err)
308+
}
309+
fmt.Println(b.String()) // {"id":1,"name":"gojay","email":"[email protected]"}
308310
}
309311
```
310312
@@ -526,7 +528,7 @@ func main() {
526528
}
527529
```
528530
529-
## Stream Encoding
531+
### Stream Encoding
530532
GoJay ships with a powerful stream encoder part of the Stream API.
531533
532534
It allows to write continuously to an io.Writer and do JIT encoding of data fed to a channel to allow async consuming. You can set multiple consumers on the channel to be as performant as possible. Consumers are non blocking and are scheduled individually in their own go routine.
@@ -553,7 +555,7 @@ type user struct {
553555
func (u *user) MarshalObject(enc *gojay.Encoder) {
554556
enc.AddIntKey("id", u.id)
555557
enc.AddStringKey("name", u.name)
556-
enc.AddStringKey("id", u.email)
558+
enc.AddStringKey("email", u.email)
557559
}
558560
func (u *user) IsNil() bool {
559561
return u == nil
@@ -589,16 +591,14 @@ func main() {
589591
s := StreamChan(make(chan *user))
590592
// start the stream encoder
591593
// will block its goroutine until enc.Cancel(error) is called
592-
// or until something is written to then channel
594+
// or until something is written to the channel
593595
go enc.EncodeStream(s)
594596
// write to our MarshalerStream
595597
for i := 0; i < 1000; i++ {
596598
s<-&user{i,"username","[email protected]"}
597599
}
598600
// Wait
599-
select {
600-
case <-enc.Done():
601-
}
601+
<-enc.Done()
602602
}
603603
```
604604

0 commit comments

Comments
 (0)