Specifically, how to connect <input type="file">
with this function in Go?
I know there is "syscall/js" package, but I didn't find any examples with file reading.
func parseCSVFile(filePath string) []LabelWithFeatures {
fileContent, _ := ioutil.ReadFile(filePath)
lines := bytes.Split(fileContent, newline)
numRows := len(lines)
labelsWithFeatures := make([]LabelWithFeatures, numRows-2)
for i, line := range lines {
// skip headers
if i == 0 || i == numRows-1 {
continue
}
labelsWithFeatures[i-1] = NewLabelWithFeatures(bytes.Split(line, comma))
}
return labelsWithFeatures
}
I've wanted a satisfactory answer for this for years, finally figured it out the other night.
You can essentially boil the whole thing down to:
I wrote a little blog post about it here with the working WASM code running at the bottom
https://donatstudios.com/Read-User-Files-With-Go-WASM