Skip to content

Commit

Permalink
Merge pull request #23 from ipinfo/uman/anycast
Browse files Browse the repository at this point in the history
Add Core.Anycast field
  • Loading branch information
UmanShahzad authored Jan 29, 2021
2 parents e7d6ce2 + a2fd03d commit ff50637
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.2.1

- Added the `Core.Anycast` boolean field.

# 2.2.0

- The following functions are now private:
Expand Down
16 changes: 16 additions & 0 deletions example/get-anycast/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
"log"

"github.com/ipinfo/go/v2/ipinfo"
)

func main() {
anycast, err := ipinfo.GetIPAnycast(nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v\n", anycast)
}
2 changes: 1 addition & 1 deletion ipinfo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

const (
defaultBaseURL = "https://ipinfo.io/"
defaultUserAgent = "IPinfoClient/Go/2.2.0"
defaultUserAgent = "IPinfoClient/Go/2.2.1"
)

// A Client is the main handler to communicate with the IPinfo API.
Expand Down
17 changes: 17 additions & 0 deletions ipinfo/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Core struct {
IP net.IP `json:"ip"`
Hostname string `json:"hostname"`
Anycast bool `json:"anycast"`
City string `json:"city"`
Region string `json:"region"`
Country string `json:"country"`
Expand Down Expand Up @@ -159,6 +160,22 @@ func (c *Client) GetIPHostname(ip net.IP) (string, error) {
return core.Hostname, nil
}

/* ANYCAST */

// GetIPAnycast returns whether an IP is an anycast IP.
func GetIPAnycast(ip net.IP) (bool, error) {
return DefaultClient.GetIPAnycast(ip)
}

// GetIPAnycast returns whether an IP is an anycast IP.
func (c *Client) GetIPAnycast(ip net.IP) (bool, error) {
core, err := c.GetIPInfo(ip)
if err != nil {
return false, err
}
return core.Anycast, nil
}

/* CITY */

// GetIPCity returns the city for the specified IP.
Expand Down

0 comments on commit ff50637

Please sign in to comment.