Documentation ¶
Overview ¶
Package csvcolumn reads specified columns from a csv style input.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // ColumnUnbound is an init value of a field.Column ColumnUnbound = -2 // ColumnMissing is an field.Column value used when field.Name was not // found in the headers of the source ColumnMissing = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct { Comma rune Comment rune FieldsPerRecord int LazyQuotes bool TrimLeadingSpace bool CaseSensitiveHeader bool // contains filtered or unexported fields }
Reader keeps the configuration and state of reading from source
Example ¶
package main import ( "fmt" "strings" "github.com/loov/csvcolumn" ) func main() { source := strings.NewReader(`Index,Age,Height,Name 1,52,1.7,Alice 5,42,1.88,Bob 512,31,1.82,Charlie`) data := csvcolumn.NewReader(source) data.LazyQuotes = true name, age, height := data.String("Name"), data.Int("Age"), data.Float64("Height") for data.Next() && data.Err() == nil { fmt.Println(*name, *age, *height) } if data.Err() != nil { fmt.Println(data.Err()) } }
Output: Alice 52 1.7 Bob 42 1.88 Charlie 31 1.82
func (*Reader) Bind ¶
Bind binds a column in a csv to its matching Value struct. It's useful when you are interested in adding your own Value types.
func (*Reader) Float64 ¶
Float64 returns a pointer to an float64 field value of a given columnName which is reassigned with every Next() call.
Click to show internal directories.
Click to hide internal directories.