diff --git a/example/resproxy/main.go b/example/resproxy/main.go new file mode 100644 index 0000000..e511600 --- /dev/null +++ b/example/resproxy/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/ipinfo/go/v2/ipinfo" +) + +func main() { + // Get access token by signing up a free account at + // https://ipinfo.io/signup. + // Provide token as an environment variable `TOKEN`, + // e.g. TOKEN="XXXXXXXXXXXXXX" go run main.go + client := ipinfo.NewClient(nil, nil, os.Getenv("TOKEN")) + resproxy, err := client.GetResproxy("175.107.211.204") + if err != nil { + log.Fatal(err) + } + fmt.Printf("%v\n", resproxy) +} diff --git a/ipinfo/resproxy.go b/ipinfo/resproxy.go new file mode 100644 index 0000000..05356c6 --- /dev/null +++ b/ipinfo/resproxy.go @@ -0,0 +1,46 @@ +package ipinfo + +// ResproxyDetails represents residential proxy detection details for an IP. +type ResproxyDetails struct { + IP string `json:"ip"` + LastSeen string `json:"last_seen"` + PercentDaysSeen float64 `json:"percent_days_seen"` + Service string `json:"service"` +} + +// GetResproxy returns the residential proxy details for the specified IP. +func GetResproxy(ip string) (*ResproxyDetails, error) { + return DefaultClient.GetResproxy(ip) +} + +// GetResproxy returns the residential proxy details for the specified IP. +func (c *Client) GetResproxy(ip string) (*ResproxyDetails, error) { + // perform cache lookup. + cacheKey := cacheKey("resproxy:" + ip) + if c.Cache != nil { + if res, err := c.Cache.Get(cacheKey); err == nil { + return res.(*ResproxyDetails), nil + } + } + + // prepare req + req, err := c.newRequest(nil, "GET", "resproxy/"+ip, nil) + if err != nil { + return nil, err + } + + // do req + v := new(ResproxyDetails) + if _, err := c.do(req, v); err != nil { + return nil, err + } + + // cache req result + if c.Cache != nil { + if err := c.Cache.Set(cacheKey, v); err != nil { + return v, err + } + } + + return v, nil +}