Skip to content

Commit

Permalink
docs(examples): add package example
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Nov 7, 2021
1 parent c845034 commit 18e6abe
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,22 @@ func ExampleDecoder_Base64() {
// Output:
// Hello
}

func Example() {
var e jx.Encoder
e.ObjStart()
e.ObjField("data")
e.Base64([]byte("hello"))
e.ObjEnd()
fmt.Println(e)

if err := jx.DecodeBytes(e.Bytes()).Obj(func(d *jx.Decoder, key string) error {
v, err := d.Base64()
fmt.Printf("%s: %s\n", key, v)
return err
}); err != nil {
panic(err)
}
// Output: {"data":"aGVsbG8="}
// data: hello
}

0 comments on commit 18e6abe

Please sign in to comment.