39 lines
756 B
Go
39 lines
756 B
Go
package repository
|
|
|
|
import (
|
|
"bufio"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func GetCsvDatas(selections []string) {
|
|
//selections := []string{"SITE_NUM", "VREF_BF", "IB_VOR_BF", "SOFT_BIN"}
|
|
f, err := os.Open("./SY8821-QLGKRN_CQ774P.1_FT.csv")
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
defer f.Close()
|
|
scanner := bufio.NewScanner(f)
|
|
m := make(map[string]int)
|
|
datas := make([]map[string]string, 0)
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
s := strings.Split(line, ",")
|
|
if len(m) == 0 {
|
|
for index, cell := range s {
|
|
if index == len(s)-1 {
|
|
continue
|
|
}
|
|
m[cell] = index
|
|
}
|
|
continue
|
|
}
|
|
data := make(map[string]string)
|
|
for _, selection := range selections {
|
|
data[selection] = s[m[selection]]
|
|
}
|
|
datas = append(datas, data)
|
|
}
|
|
}
|