diff options
Diffstat (limited to 'monitor')
-rw-r--r-- | monitor/database.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/monitor/database.go b/monitor/database.go index 7a0ead1..1c2a913 100644 --- a/monitor/database.go +++ b/monitor/database.go @@ -10,14 +10,23 @@ import ( "golang.org/x/mod/sumdb/tlog" ) +const userAgent = "gosumdbaudit/1.0 (+https://bnbl.io/gosumdbaudit)" + type Database struct { URL string Key string + + c http.Client } func (db *Database) readRemote(path string) ([]byte, error) { log.Printf("GET %s", path) - resp, err := http.Get("https://" + db.URL + path) + req, err := http.NewRequest(http.MethodGet, "https://"+db.URL+path, nil) + if err != nil { + return nil, err + } + req.Header.Set("user-agent", userAgent) + resp, err := db.c.Do(req) if err != nil { return nil, err } @@ -30,7 +39,7 @@ func (db *Database) readRemote(path string) ([]byte, error) { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("get %s: %v", err) + return nil, fmt.Errorf("get %s: %v", path, err) } return body, nil } |