Documentation
¶
Overview ¶
Package csv converts slices of values into CSV text. Converter construction rejects cyclic row types before gocsv can recurse until the process dies. The marshal boundary turns other gocsv panics, including panics from caller MarshalCSV methods, into errors. Valid csv[] expansion remains supported.
Index ¶
Examples ¶
Constants ¶
View Source
const Name = "csv"
Name identifies the CSV converter.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CSV ¶
type CSV[In any] struct { // IConverter provides the converter lifecycle and execution API. converter.IConverter[In, string] `json:"converter" validate:"required"` }
CSV converts its input into CSV text.
func New ¶
New creates a converter from []In to CSV text. Options are applied and validated by converter.New.
Example ¶
Demonstrates marshaling a slice of structs as CSV text.
type product struct {
Name string `csv:"name"`
Price int `csv:"price"`
}
products, err := New[product]()
if err != nil {
log.Fatalln(err)
}
out, err := products.Run(context.Background(), []product{
{Name: "tea", Price: 4},
{Name: "coffee", Price: 6},
})
if err != nil {
log.Fatalln(err)
}
fmt.Print(out)
Output: name,price tea,4 coffee,6
Click to show internal directories.
Click to hide internal directories.