-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreaches.go
More file actions
31 lines (27 loc) · 806 Bytes
/
breaches.go
File metadata and controls
31 lines (27 loc) · 806 Bytes
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
package xposedornot
import (
"context"
"encoding/json"
"fmt"
"net/url"
"strings"
)
// GetBreaches retrieves a list of known data breaches. If domain is non-empty,
// results are filtered to breaches affecting that domain.
func (c *Client) GetBreaches(ctx context.Context, domain string) (*GetBreachesResponse, error) {
reqURL := fmt.Sprintf("%s/v1/breaches", c.baseURL)
domain = strings.TrimSpace(domain)
if domain != "" {
params := url.Values{"domain": {domain}}
reqURL += "?" + params.Encode()
}
body, err := c.doRequest(ctx, "GET", reqURL)
if err != nil {
return nil, fmt.Errorf("get breaches: %w", err)
}
var resp GetBreachesResponse
if err := json.Unmarshal(body, &resp); err != nil {
return nil, fmt.Errorf("get breaches: parsing response: %w", err)
}
return &resp, nil
}