csv

package
v4.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 7 Imported by: 0

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 Must

func Must[In any](
	opts ...converter.Func[[]In, string],
) *CSV[[]In]

Must creates a CSV converter or panics if validation fails.

func New

func New[In any](
	opts ...converter.Func[[]In, string],
) (*CSV[[]In], error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址