Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWriter ¶ added in v0.1.2
NewWriter creates a writer which appends records to a CSV raw file.
As returned by NewWriter, a csv.Writer writes records terminated by a newline and uses ',' as the field delimiter. The exported fields can be changed to customize the details before the first call to Write or WriteAll.
Comma is the field delimiter.
If UseCRLF is true, the csv.Writer ends each record with \r\n instead of \n.
Example ¶
var buf bytes.Buffer w := NewWriter(&buf) w.Write([]string{"foo", "bar"}) w.Flush() fmt.Println(buf.String())
Output: foo,bar
Types ¶
type CreationOpts ¶
CreationOpts defines functional options for creating Tables.
func ConsiderInitialSpace ¶ added in v1.1.2
func ConsiderInitialSpace() CreationOpts
ConsiderInitialSpace configures the CSV parser to treat the whitespace immediately after a delimiter as part of the following field.
func Delimiter ¶ added in v1.1.2
func Delimiter(d rune) CreationOpts
Delimiter specifies the character sequence which should separate fields (aka columns).
func LoadHeaders ¶
func LoadHeaders() CreationOpts
LoadHeaders uses the first line of the CSV as table headers. The header line will be skipped during iteration
func SetHeaders ¶
func SetHeaders(headers ...string) CreationOpts
SetHeaders sets the table headers.
type Source ¶
type Source func() (io.ReadCloser, error)
Source defines a table physical data source.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a Table backed by a CSV physical representation.
func NewTable ¶ added in v0.1.2
func NewTable(source Source, opts ...CreationOpts) (*Table, error)
NewTable creates a table.Table from the CSV table physical representation. CreationOpts are executed in the order they are declared. If a dialect is not configured via SetDialect, DefautltDialect is used.
func (*Table) Iter ¶
Iter returns an Iterator to read the table. Iter returns an error if the table physical source can not be iterated. The iteration process always start at the beginning of the CSV and is backed by a new reading.
Example ¶
table, _ := NewTable(FromString("\"name\"\nfoo\nbar"), LoadHeaders()) iter, _ := table.Iter() defer iter.Close() for iter.Next() { fmt.Println(iter.Row()) }
Output: [foo] [bar]
func (*Table) ReadAll ¶ added in v0.1.2
ReadAll reads all rows from the table and return it as strings.
Example ¶
table, _ := NewTable(FromString("\"name\"\nfoo\nbar"), LoadHeaders()) rows, _ := table.ReadAll() fmt.Print(rows)
Output: [[foo] [bar]]
func (*Table) ReadColumn ¶ added in v1.1.2
ReadColumn reads a specific column from the table and return it as strings.
Example ¶
table, _ := NewTable(FromString("name,age\nfoo,25\nbar,48"), LoadHeaders()) cols, _ := table.ReadColumn("name") fmt.Print(cols)
Output: [foo bar]