Skip to content

Instantly share code, notes, and snippets.

@keltia

keltia/parse.go Secret

Created October 17, 2017 15:40
Show Gist options
  • Save keltia/f1dcb745fdef27d5fb2da76b17c9c124 to your computer and use it in GitHub Desktop.
Save keltia/f1dcb745fdef27d5fb2da76b17c9c124 to your computer and use it in GitHub Desktop.
Code reading a csv file with csvplus
fields = []string{
"EmailAddress",
"Guid",
"FirstSyncTime",
"LastSuccessSync",
"DeviceType",
"Identity",
"DeviceUserAgent",
"DeviceModel",
"DeviceFriendlyName",
"DeviceOS",
"DeviceAccessState",
"DeviceAccessStateReason",
}
...
func loadCSV(ctx *Context, fn string) (err error) {
// clear all variables & caches
reset()
// Plain csvplus.FromFile(fn).Delimiter(';') didn't work
allLines := csvplus.FromFile(fn).Delimiter(';').NumFields(38).SelectColumns(fields...)
rows, err := csvplus.Take(allLines).ToRows()
if err != nil {
log.Printf("error loading %s: %v", fn, err)
return
}
if fDebug {
log.Printf("read %d lines…\n", len(rows))
}
// insert
for _, row := range rows {
if fDebug {
log.Printf("row=%v\n", row) // <<<<<< here, row was {}
}
guid, e := NewDevice(row)
if guid == "" || e == nil {
log.Fatalf("error creating %s: %v", guid, e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment