Caching added.

JSON File export will append, not truncate.
This commit is contained in:
Musab Gültekin
2019-06-08 15:29:09 +03:00
parent 9e61a96412
commit ca197ff06a
6 changed files with 42 additions and 18 deletions

View File

@ -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)