a lib convert go struct to csv file

the struct like this

type testStruct struct {    A1 int    A2 bool    B1 []int    B2 []struct {        B21 int        B22 string    }    B3 []*struct {        B31 []*int    }}

after the transformation, the header like follow



  • support a struct or map slice convert to csv
  • supports header mapping to custom types
  • support protobuf struct

how to use

type struct User {    ID   string    Name string}func Converter(input []User) error {    conv, err := struct2csv.NewStructConverter(struct2csv.NewHeaderOriginalStringConv(), struct2csv.WithResultCap(len(input)))    if err != nil {        return err    }    results, err := conv.Convert(input)    if err != nil {        return error    }    defer results.Reset()    f, err := os.Create("test.csv")    if err != nil {        return err    }    defer f.Close()    return struct2csv.NewCSVWriter(f).WriteCSV(results)}




View Github