mirror of
https://github.com/imjasonh/csvstruct
synced 2026-07-09 11:26:34 +00:00
add example
This commit is contained in:
parent
f12bbf25ba
commit
fa178edcf9
1 changed files with 21 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package csvstruct
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
|
@ -126,3 +127,23 @@ a,b`)).DecodeNext(&r); err != nil {
|
|||
t.Errorf("unexpected results, got %v", r)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleDecoder_DecodeNext() {
|
||||
csv := `Foo,Bar,Baz
|
||||
a,b,c
|
||||
d,e,f`
|
||||
type row struct {
|
||||
Foo, Bar, Baz string
|
||||
}
|
||||
var r row
|
||||
d := NewDecoder(strings.NewReader(csv))
|
||||
for {
|
||||
if err := d.DecodeNext(&r); err == io.EOF {
|
||||
break
|
||||
}
|
||||
fmt.Println(r)
|
||||
}
|
||||
// Output:
|
||||
// {a b c}
|
||||
// {d e f}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue