I am looking for feedback for an additional api for encoding/csv.
Example:
type CSVStrategy func(string, CSVRow)
type Foo struct {
name string
date Date
number int
}
interface CSVParsable {
func CSVStrategies() map[string]CSVStrategy
}
type CSVRow struct {
header *map[string]int
row []string
}
func (r *CSVRow) At(i int) string {
return r.row[i]
}
func (r *CSVRow) Fetch(name string) string {
return r.row[r.header[name]]
}
func (f *Foo) CSVStrategies() map[string]CSVStrategy {
strategies := map[string]CSVStrategy {
"name": func(field string, r CSVRow) {
f.name = field
},
"date": func(field string, r CSVRow) {
d := r.Fetch("date")
if d == nil {
d = r.Fetch("adjusted_date")
}
f.date = date.Parse(d)
},
"date": func(field string, r CSVRow) {
f.date = int.Parse(field)
},
}
return strategies
}
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.