Documentation ¶
Overview ¶
A CSV implementation inspired by Python's CSV module. Supports custom CSV formats.
Example (ReadingWriting) ¶
buf := bytes.Buffer{} writer := csv.NewWriter(&buf) writer.Write([]string{"Hello", "World", "!"}) writer.Flush() reader := csv.NewReader(&buf) columns, err := reader.Read() if err != nil { panic(err) } for _, s := range columns { fmt.Println(s) }
Output: Hello World !
Index ¶
Examples ¶
Constants ¶
const ( QuoteDefault = iota // See DefaultQuoting. QuoteAll = iota // Quotes around every field. QuoteMinimal = iota // Quotes when needed. QuoteNonNumeric = iota // Quotes around non-numeric fields. // Never quote. Use with care. Could make things unparsable. QuoteNone = iota )
Values Dialect.Quoting can take.
const ( DoubleQuoteDefault = iota // See DefaultDoubleQuote. DoDoubleQuote = iota // Escape using double escape characters. NoDoubleQuote = iota // Escape using escape character. )
Values Dialect.DoubleQuote can take.
const ( DefaultDelimiter = ' ' DefaultQuoting = QuoteMinimal DefaultDoubleQuote = DoDoubleQuote DefaultEscapeChar = '\\' DefaultQuoteChar = '"' DefaultLineTerminator = "\n" )
Default dialect.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect struct { // The delimiter that separates each field from another. Defaults to // DefaultDelimiter. Delimiter rune // What quoting mode to use. Defaults to DefaultQuoting. Quoting int // How to escape quotes. Defaults to DefaultDoubleQuote. DoubleQuote int // Character to use for escaping. Only used if DoubleQuote==NoDoubleQuote. // Defaults to DefaultEscapeChar. EscapeChar rune // Character to use as quotation mark around quoted fields. Defaults to // DefaultQuoteChar. QuoteChar rune // String that separates each record in a CSV file. Defaults to // DefaultLineTerminator. LineTerminator string }
A Dialect specifies the format of a CSV file. This structure is used by a Reader or Writer to know how to operate on the file they are reading/writing.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader reads records from a CSV-encoded file.
Can be created by calling either NewReader or using NewDialectReader.
func NewDialectReader ¶
Create a custom CSV reader.
func NewReader ¶
Creates a reader that conforms to RFC 4180 and behaves identical as a encoding/csv.Reader.
See `Default*` constants for default dialect used.
func (*Reader) Read ¶
Read reads one record from r. The record is a slice of strings with each string representing one field.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer writes records to a CSV encoded file.
Can be created by calling either NewWriter or using NewDialectWriter.
func NewDialectWriter ¶
Create a custom CSV writer.
func NewWriter ¶
Create a writer that conforms to RFC 4180 and behaves identical as a encoding/csv.Reader.
See `Default*` constants for default dialect used.
func (Writer) Flush ¶
func (w Writer) Flush()
Flush writes any buffered data to the underlying io.Writer. To check if an error occurred during the Flush, call Error.
Directories ¶
Path | Synopsis |
---|---|
Helpers that makes it easy to build CSV dialects.
|
Helpers that makes it easy to build CSV dialects. |
Interfaces shared among go-csv and the Go standard library's encoding/csv.
|
Interfaces shared among go-csv and the Go standard library's encoding/csv. |