@@ -12,13 +12,15 @@ const baseURL = "https://vpnapi.io/api/"
1212
1313var ErrRateLimited = errors .New ("rate limited, try again later" )
1414
15+ // The security section of a response
1516type Security struct {
1617 VPN bool `json:"vpn"`
1718 Proxy bool `json:"proxy"`
1819 Tor bool `json:"tor"`
1920 Relay bool `json:"relay"`
2021}
2122
23+ // The location section of a response
2224type Location struct {
2325 City string `json:"city"`
2426 Region string `json:"region"`
@@ -34,27 +36,32 @@ type Location struct {
3436 IsInEuropeanUnion bool `json:"is_in_european_union"`
3537}
3638
39+ // The network section of a response
3740type Network struct {
3841 Network string `json:"network"`
3942 AutonomousSystemNumber string `json:"autonomous_system_number"`
4043 AutonomousSystemOrganization string `json:"autonomous_system_organization"`
4144}
4245
46+ // The response type returned from a query
4347type Response struct {
4448 IP string `json:"ip"`
4549 Security Security `json:"security"`
4650 Location Location `json:"location"`
4751 Network Network `json:"network"`
4852}
4953
54+ // Client makes queries to the API.
5055type Client struct {
5156 apiKey string
5257}
5358
59+ // New creates a new Client. Obtain an API key by registering at vpnapi.io.
5460func New (apiKey string ) * Client {
5561 return & Client {apiKey : apiKey }
5662}
5763
64+ // Query queries the API for details about ip.
5865func (c * Client ) Query (ip string ) (* Response , error ) {
5966 resp , err := http .Get (baseURL + ip + "?" + c .apiKey )
6067 if err != nil {
@@ -81,35 +88,3 @@ func (c *Client) Query(ip string) (*Response, error) {
8188
8289 return ret , nil
8390}
84-
85- /*
86- {
87- "ip": "8.8.8.8",
88- "security": {
89- "vpn": false,
90- "proxy": false,
91- "tor": false,
92- "relay": false,
93- },
94- "location": {
95- "city": "",
96- "region": "",
97- "country": "United States",
98- "continent": "North America",
99- "region_code": "",
100- "country_code": "US",
101- "continent_code": "NA",
102- "latitude": "37.7510",
103- "longitude": "-97.8220",
104- "time_zone": "America/Chicago",
105- "locale_code": "en",
106- "metro_code": "",
107- "is_in_european_union": false
108- },
109- "network": {
110- "network": "8.8.8.0/24",
111- "autonomous_system_number": "AS15169",
112- "autonomous_system_organization": "GOOGLE"
113- }
114- }
115- */
0 commit comments