Caching added.
JSON File export will append, not truncate.
This commit is contained in:
17
export.go
17
export.go
@ -4,14 +4,21 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var file *os.File
|
||||
var once sync.Once
|
||||
|
||||
func Export(response *Response) {
|
||||
file, err := os.Create("out.json")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "output file creation error: %v", err)
|
||||
return
|
||||
}
|
||||
once.Do(func() {
|
||||
newFile, err := os.OpenFile("out.json", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "output file creation error: %v", err)
|
||||
return
|
||||
}
|
||||
file = newFile
|
||||
})
|
||||
|
||||
for res := range response.Exports {
|
||||
//fmt.Println(res)
|
||||
|
Reference in New Issue
Block a user