-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStoreJsonResults.go
35 lines (31 loc) · 916 Bytes
/
StoreJsonResults.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
package main
import (
"encoding/json"
"io/ioutil"
)
type Query struct {
Departure string
Arrival string
DepartureTime string
Email string
}
// StoreJSONResults stores a list of results in a json file
func StoreJSONResults(results []FlightResult, filename string) {
jsonString, err := json.MarshalIndent(results, "", "\t")
LogErrorIfNotNull(err)
err = ioutil.WriteFile(filename, jsonString, 0644)
LogErrorIfNotNull(err)
}
// StoreJSONQueries stores a list of queries in a json file
func StoreJSONQueries(searchInput SearchInput, recipient string, filename string) {
query := Query{
Departure: searchInput.Departure,
Arrival: searchInput.Arrival,
DepartureTime: searchInput.Date,
Email: recipient,
}
jsonString, err := json.MarshalIndent(query, "", "\t")
LogErrorIfNotNull(err)
err = ioutil.WriteFile(filename, jsonString, 0644)
LogErrorIfNotNull(err)
}