Geolocation API
The Geolocation API provides real-time look up of geographical locations using IP addresses.
Get location by IP
GeoLocationOptions) (*IPLocation, error)
func (c *GeoLocation) Get(ip string, options *Looks up geolocation for an IP address.
Arguments
Parameter | Type | Description | Required |
---|---|---|---|
ip | string | The IP address or domain name to look up. | Yes |
options | struct | Pointer to a struct of GeoLocationOptions | No |
Returns
This call returns an IPLocation object and an Error object.
Example
package main
import (
"fmt"
"github.com/salesfly/salesfly-go"
)
func main() {
apiKey := "YOUR-API-KEY"
client, err := salesfly.NewClient(apiKey, nil)
options := &salesfly.GeoLocationOptions{
DisplayFields: "country_code", // Return only country code
}
result, err := client.GeoLocation.Get("8.8.8.8", options)
if err != nil {
panic("Failed to get IP location")
}
fmt.Println("Country code:", result.CountryCode)
}
Get location of multiple IP addresses
GeoLocationOptions) ([]iplocation, error)
func (c *GeoLocation) GetBulk(iplist []string, options *Looks up geolocation for multiple IP addresses.
Arguments
Parameter | Type | Description | Required |
---|---|---|---|
iplist | []string | The IP addresses or domain names to look up. | Yes |
options | struct | Pointer to a struct of GeoLocationOptions | No |
Returns
This call returns an array of IPLocation objects and an Error object.
Example
package main
import (
"fmt"
"github.com/salesfly/salesfly-go"
)
func main() {
apiKey := "YOUR-API-KEY"
client, err := salesfly.NewClient(apiKey, nil)
result, err := client.GeoLocation.GetBulk([]string{"1.2.3.4", "8.8.8.8"}, nil)
if err != nil {
panic("Failed to get IP location")
}
for _, v := range result {
fmt.Printf("Location: %+v\n", v)
}
}
Get location of caller
GeoLocationOptions) (*IPLocation, error)
func (c *GeoLocation) GetCurrent(options *Get geolocation of caller's current IP address.
Arguments
Parameter | Type | Description | Required |
---|---|---|---|
options | struct | Pointer to a struct of GeoLocationOptions | No |
Returns
This call returns an IPLocation object and an Error object.
Example
package main
import (
"fmt"
"github.com/salesfly/salesfly-go"
)
func main() {
apiKey := "YOUR-API-KEY"
client, err := salesfly.NewClient(apiKey, nil)
result, err := client.GeoLocation.GetCurrent(nil)
if err != nil {
panic("Failed to get IP location")
}
fmt.Printf("Location: %+v\n", result)
}
← API Client PDF API →