forked from GovAuCSU/ctlog-acquisition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctlist.go
57 lines (49 loc) · 1.13 KB
/
ctlist.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
53
54
55
56
57
package ctlogacquisition
import (
"encoding/json"
"io/ioutil"
"net/http"
"time"
)
// GOLANG tips: if your json
type stream struct {
url string
min int
max int
current int
count int
}
type ctlist struct {
Logs []ctlistendpoint `json:"logs"`
Operators []operator `json:"operators"`
}
type ctlistendpoint struct {
Description string `json:"description"`
Key string `json:"key"`
Url string `json:"url"`
Maximum_merge_delay int `json:"maximum_merge_delay"`
Operated_by []int `json:"operated_by"`
}
type operator struct {
Name string `json:"name"`
Id int `json:"id"`
}
func GetListCT() (*ctlist, error) {
url := "https://www.gstatic.com/ct/log_list/log_list.json"
// Using http.Client so we can modify timeout value
httpclient := http.Client{
Timeout: time.Second * 2, // Maximum of 2 secs timeout
}
resp, err := httpclient.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
var list ctlist
json.Unmarshal([]byte(body), &list)
if err != nil {
return nil, err
}
return &list, nil
}