Skip to content

Commit

Permalink
An example for using the encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed May 21, 2014
1 parent f690c49 commit 6c5a10f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,28 @@ func encodeExpected(
label, wantStr, got)
}
}

func ExampleEncoder_Encode() {
date, _ := time.Parse(time.RFC822, "14 Mar 10 18:00 EST")
var config = map[string]interface{}{
"date": date,
"counts": []int{1, 1, 2, 3, 5, 8},
"hash": map[string]string{
"key1": "val1",
"key2": "val2",
},
}
buf := new(bytes.Buffer)
if err := NewEncoder(buf).Encode(config); err != nil {
log.Fatal(err)
}
fmt.Println(buf.String())

// Output:
// counts = [1, 1, 2, 3, 5, 8]
// date = 2010-03-14T23:00:00Z
//
// [hash]
// key1 = "val1"
// key2 = "val2"
}

0 comments on commit 6c5a10f

Please sign in to comment.