go-quote
go-quote copied to clipboard
Reading From CSV files into quote object causes error
When reading a csv file into a quote object there is a slight error which needs to be checked before reading the file.
NewQuoteFromCSV(symbol, csv string) (Quote, error) {
tmp := strings.Split(csv, "\n")
numrows := len(tmp)
q := NewQuote(symbol, numrows-1)
for row, bar := 1, 0; row < numrows; row, bar = row+1, bar+1 {
line := strings.Split(tmp[row], ",") # we need to add in a conditional check as such
if len(line) != 6 {
break
}
The reason being is that the way that the "records" are being written a "\n" is automatically appended at the end, this simple check worked and helped me avoid the annoying out of bounds error.