-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
53 lines (40 loc) · 888 Bytes
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"bufio"
"encoding/csv"
"os"
)
type LogData struct {
LogTime string `bson:"log_time"`
DeviceName string `bson:"device_name"`
AttacName string `bson:"attack_name"`
RawPacket string `bson:"raw_packet"`
}
// ReadCSV read csv to row
func ReadCSV(fileName string) []interface{} {
// totalResult []
var logDataResult []interface{}
csvData, _ := os.Open("./bigdatasample/" + fileName)
rdr := csv.NewReader(bufio.NewReader(csvData))
rows, _ := rdr.ReadAll()
for i, row := range rows {
if i == 0 {
continue
}
logData := &LogData{}
for j := range row {
switch j {
case 1:
logData.LogTime = rows[i][j]
case 2:
logData.DeviceName = rows[i][j]
case 3:
logData.AttacName = rows[i][j]
case 4:
logData.RawPacket = rows[i][j]
}
}
logDataResult = append(logDataResult, logData)
}
return logDataResult
}