-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (43 loc) · 1009 Bytes
/
main.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
package main
import (
"encoding/json"
"indexer/consumer/events"
"io"
"log"
"os"
)
func main() {
parsed_json := unmarshal()
log.Println(parsed_json)
}
// func getObject() ( Person) {
// r, err := http.Get("https://swapi.dev/api/people/1")
// check(err, "Calling SW people API")
// defer r.Body.Close()
// data, err := io.ReadAll(r.Body)
// check(err, "Read JSON from response")
// err = json.Unmarshal(data, &person)
// check(err, "Unmarshalling")
// return
// }
func unmarshal() (checkpoint events.TransferObject) {
file, err := os.Open("events/samples/transfer_object.json")
if err != nil {
log.Println("Error opening json file:", err)
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
log.Println("Error reading json data:", err)
}
err = json.Unmarshal(data, &checkpoint)
if err != nil {
log.Println("Error unmarshalling json data:", err)
}
return
}
func check(err error, msg string) {
if err != nil {
log.Println("Error encountered:", msg)
}
}