Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cuixin/csv4g
csv files mapping/unmarshal to struct data in golang.
https://github.com/cuixin/csv4g
csv golang marshal structure unmarshall
Last synced: 2 months ago
JSON representation
csv files mapping/unmarshal to struct data in golang.
- Host: GitHub
- URL: https://github.com/cuixin/csv4g
- Owner: cuixin
- Created: 2013-11-28T06:51:48.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2020-03-10T14:41:41.000Z (almost 5 years ago)
- Last Synced: 2023-03-23T23:57:40.653Z (almost 2 years ago)
- Topics: csv, golang, marshal, structure, unmarshall
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 7
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
csv4g
=======A csv file mapping to struct tool.
installation
------------go get github.com/cuixin/csv4g
example
-------```
package mainimport (
"fmt""github.com/cuixin/csv4g"
)type Test struct {
Id int
Name string
Desc string
Go string
Num float32
Foo bool
SliceInt []int
SliceFloat32 []float32 `csv:"sliceFloat32"`
IgnoreField string `csv:"-"`
CustomField string `csv:"custom,omitempty"`
EmptyField string `csv:"omitempty"`
}func main() {
csv, err := csv4g.NewWithOpts("test.csv", Test{}, csv4g.Comma(','), csv4g.LazyQuotes(true), csv4g.SkipLine(1))
if err != nil {
fmt.Printf("Error %v\n", err)
return
}
for i := 0; i < csv.LineLen; i++ {
tt := &Test{}
err = csv.Parse(tt)
if err != nil {
fmt.Printf("Error on parse %v\n", err)
return
}
fmt.Println(tt)
}
}```