-
-
Save keltia/f1dcb745fdef27d5fb2da76b17c9c124 to your computer and use it in GitHub Desktop.
Code reading a csv file with csvplus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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