-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple integration for map endpoint.
- Loading branch information
1 parent
0e66ea4
commit be16a8e
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# 2.4.0 | ||
|
||
- Added support for IP Map API. | ||
|
||
# 2.3.2 | ||
|
||
- Added the `Core.Bogon` boolean field. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ipinfo | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"net" | ||
) | ||
|
||
// IPMap is the full JSON response from the IP Map API. | ||
type IPMap struct { | ||
Status string `json:"status"` | ||
ReportURL string `json:"reportUrl"` | ||
} | ||
|
||
// GetIPMap returns an IPMap result for a group of IPs. | ||
// | ||
// `len(ips)` must not exceed 500,000. | ||
func GetIPMap(ips []net.IP) (*IPMap, error) { | ||
return DefaultClient.GetIPMap(ips) | ||
} | ||
|
||
// GetIPMap returns an IPMap result for a group of IPs. | ||
// | ||
// `len(ips)` must not exceed 500,000. | ||
func (c *Client) GetIPMap(ips []net.IP) (*IPMap, error) { | ||
if len(ips) > 500000 { | ||
return nil, errors.New("ip count must be <500,000") | ||
} | ||
|
||
jsonArrStr, err := json.Marshal(ips) | ||
if err != nil { | ||
return nil, err | ||
} | ||
jsonBuf := bytes.NewBuffer(jsonArrStr) | ||
|
||
req, err := c.newRequest(nil, "POST", "map?cli=1", jsonBuf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Header.Set("Content-Type", "application/json") | ||
|
||
result := new(IPMap) | ||
if _, err := c.do(req, result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |