-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfs_handler.go
More file actions
28 lines (24 loc) · 740 Bytes
/
Copy pathfs_handler.go
File metadata and controls
28 lines (24 loc) · 740 Bytes
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
package main
import (
"fmt"
"os"
"strconv"
)
// SaveChunkToFile - goroutine that that performs saving data to file on local file system
// It is brought to life each time there is completed chunk of data in accumulator
func SaveChunkToFile(chunk []string, fileCount int) {
defer RecoverAnyPanic("SaveChunkToFile")
// create new file
f, err := os.Create(fmt.Sprintf("%s/%sflow.json", Config.Output.LocalFS.Path, strconv.Itoa(fileCount)))
if err != nil {
LogOnError("SaveChunkToFile", err)
return
}
defer f.Close()
// feed file with JSON array of decoded flows
f.WriteString("[")
for _, jSon := range chunk {
f.WriteString(fmt.Sprintf("%s,", jSon))
}
f.WriteString("{}]") // dirty trick that makes JSON always valid
}