CSV
Generic CSV marshal/unmarshal over the standard library's encoding/csv. Columns come from the csv:"name" struct tag (falling back to the field name); csv:"-" skips a field.
Marshal
go
type Row struct {
Name string `csv:"name"`
Age int `csv:"age"`
Active bool `csv:"active"`
Secret string `csv:"-"` // omitted
}
rows := []Row{{Name: "alice", Age: 30, Active: true}}
var buf bytes.Buffer
if err := core.CSVMarshal(&buf, rows); err != nil {
return err
}
// buf:
// name,age,active
// alice,30,trueWriting to an HTTP response:
go
func Export(c core.IHTTPContext) error {
c.Response().Header().Set("Content-Type", "text/csv")
return core.CSVMarshal(c.Response(), rows)
}Unmarshal
Columns are matched by header name against the tags:
go
rows, err := core.CSVUnmarshal[Row](reader)API
go
func CSVMarshal[T any](w io.Writer, rows []T) IError
func CSVUnmarshal[T any](r io.Reader) ([]T, IError)Supported field kinds: string, bool, all int/uint sizes, and floats.