-
Notifications
You must be signed in to change notification settings - Fork 6
/
prefetcher.go
47 lines (42 loc) · 937 Bytes
/
prefetcher.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
// only used in JSON
type Record struct {
Name string
Type string
Class string
Ttl uint32
Data string
}
func prefetch(zs *ZoneStore, critical bool) {
log.Printf("Loading zones from %s...\n", zoneUrl)
resp, err := http.Get(zoneUrl)
if err != nil && critical {
log.Fatal(err)
} else if err != nil {
log.Println(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil && critical {
log.Fatal(err)
} else if err != nil {
log.Println(err)
}
tmpmap := make(map[string][]Record)
err = json.Unmarshal(body, &tmpmap)
if err != nil && critical {
log.Fatal("Error parsing JSON zones file: ", err, string(body))
} else if err != nil {
log.Println("Error parsing JSON zones file: ", err)
return
}
zs.apply(tmpmap, true)
dbWriteZones(tmpmap, true)
log.Printf("Loaded %d zones in memory", len(tmpmap))
}