func (c *Client) CheckDays(ip string, days int) ([]Report, error) {
	if ip := net.ParseIP(ip); ip == nil {
		return nil, errors.New("invalid Report.IPAddress: invalid IP")
	}

	v := url.Values{"key": {c.APIKey}}
	if days >= 1 {
		v.Set("days", strconv.Itoa(days))
	}
	u := fmt.Sprintf("%s/check/%s/json", baseURL, ip)
	req, err := http.NewRequest(http.MethodPost, u, strings.NewReader(v.Encode()))
	if err != nil {
		return nil, err
	}
	req.Header.Set("User-Agent", DefaultUserAgent)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Accept", "application/json")

	resp, err := c.http.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	if resp.StatusCode >= 400 && resp.StatusCode < 600 {
		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return nil, err
		}
		return nil, RequestError{resp.Status, body}
	}

	var buf bytes.Buffer
	_, err = io.Copy(&buf, resp.Body)
	if err != nil {
		return nil, err
	}

	// Figure out what the type of the JSON root is (array or object),
	// so that we can unmarshal it correctly into either []Report or Report.
	// typ=0: default value (error!)
	// typ=1: array
	// typ=2: object
	var typ int
	for _, b := range buf.Bytes() {
		if b == '[' {
			typ = 1
			break
		} else if b == '{' {
			typ = 2
			break
		}
	}
	if typ == 0 {
		return nil, fmt.Errorf("JSON root isn't an object or an array: %s", buf.String())
	}

	var (
		reports []Report
		dec     = json.NewDecoder(&buf)
	)
	if typ == 1 {
		err = dec.Decode(&reports)
	} else {
		var r Report
		err = dec.Decode(&r)
		reports = append(reports, r)
	}
	return reports, err
}
// CheckDays queries AbuseIPDB for reports of an IP address.
// If days is less than 1, the parameter will be not be sent
// and the default value chosen by the API is used.
// If using the default value, use method Check instead.
CheckDays queries AbuseIPDB for reports of an IP address.
If days is less than 1, the parameter will be not be sent
and the default value chosen by the API is used.
If using the default value, use method Check instead.
// CheckDays queries AbuseIPDB for reports of an IP address . // If days is less than 1 the parameter will be not be sent // and the default value chosen by the API is used . // If using the default value use method Check instead .
func (c *Client) CheckDays(ip string, days int) ([]Report, error) {
	if ip := net.ParseIP(ip); ip == nil {
		return nil, errors.New("invalid Report.IPAddress: invalid IP")
	}
	v := url.Values{"key": {c.APIKey}}
	if days >= 1 {
		v.Set("days", strconv.Itoa(days))
	}
	u := fmt.Sprintf("%s/check/%s/json", baseURL, ip)
	req, err := http.NewRequest(http.MethodPost, u, strings.NewReader(v.Encode()))
	if err != nil {
		return nil, err
	}
	req.Header.Set("User-Agent", DefaultUserAgent)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Accept", "application/json")
	resp, err := c.http.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode >= 400 && resp.StatusCode < 600 {
		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return nil, err
		}
		return nil, RequestError{resp.Status, body}
	}
	var buf bytes.Buffer
	_, err = io.Copy(&buf, resp.Body)
	if err != nil {
		return nil, err
	}
	var typ int
	for _, b := range buf.Bytes() {
		if b == '[' {
			typ = 1
			break
		} else if b == '{' {
			typ = 2
			break
		}
	}
	if typ == 0 {
		return nil, fmt.Errorf("JSON root isn't an object or an array: %s", buf.String())
	}
	var (
		reports []Report
		dec     = json.NewDecoder(&buf)
	)
	if typ == 1 {
		err = dec.Decode(&reports)
	} else {
		var r Report
		err = dec.Decode(&r)
		reports = append(reports, r)
	}
	return reports, err
}
func ( c * Client ) CheckDays ( ip string , days int ) ( [ ] Report , error ) { if ip := net . ParseIP ( ip ) ; ip == nil { return nil , errors . New ( " " ) } v := url . Values { " " : { c . APIKey } } if days >= 1 { v . Set ( " " , strconv . Itoa ( days ) ) } u := fmt . Sprintf ( " " , baseURL , ip ) req , err := http . NewRequest ( http . MethodPost , u , strings . NewReader ( v . Encode ( ) ) ) if err != nil { return nil , err } req . Header . Set ( " " , DefaultUserAgent ) req . Header . Set ( " " , " " ) req . Header . Set ( " " , " " ) resp , err := c . http . Do ( req ) if err != nil { return nil , err } defer resp . Body . Close ( ) if resp . StatusCode >= 400 && resp . StatusCode < 600 { body , err := ioutil . ReadAll ( resp . Body ) if err != nil { return nil , err } return nil , RequestError { resp . Status , body } } var buf bytes . Buffer _ , err = io . Copy ( & buf , resp . Body ) if err != nil { return nil , err } var typ int for _ , b := range buf . Bytes ( ) { if b == '[' { typ = 1 break } else if b == '{' { typ = 2 break } } if typ == 0 { return nil , fmt . Errorf ( " " , buf . String ( ) ) } var ( reports [ ] Report dec = json . NewDecoder ( & buf ) ) if typ == 1 { err = dec . Decode ( & reports ) } else { var r Report err = dec . Decode ( & r ) reports = append ( reports , r ) } return reports , err }
CheckDays queries AbuseIPDB for reports of an IP address.
CheckDays queries AbuseIPDB for reports of an IP address .
// Figure out what the type of the JSON root is (array or object), // so that we can unmarshal it correctly into either []Report or Report. // typ=0: default value (error!) // typ=1: array // typ=2: object