ipinfo / go Goto Github PK
View Code? Open in Web Editor NEWGo library for IPinfo API (IP geolocation and other types of IP data)
Home Page: https://pkg.go.dev/github.com/ipinfo/go/v2
License: Apache License 2.0
Go library for IPinfo API (IP geolocation and other types of IP data)
Home Page: https://pkg.go.dev/github.com/ipinfo/go/v2
License: Apache License 2.0
Apache License 2.0
Add an optional IP selection handler to the SDK client initialization step which accepts the request context and expects returning an IP.
Add a default handler for this which looks at the X-Forwarded-For
header and falls back to the source IP.
The resulting IP is the IP for which details are fetched.
Implement caching as described in IPinfo Wrapper Specs: https://github.com/ipinfo/ipinfo-wrapper-specs/blob/master/versions/01/GUIDELINES.md#caching
go-ipinfo
provides the ability to use caching using cache.Interface
and custom implementations. However it would be convenient to provide custom implementations for some popular cache engines:
Make sure the cache key contains a number to indicate the version of the cached data. Data changes that change what's expected in cached data require a version change.
$ go get github.com/ipinfo/go/v2/ipinfo
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
I am using the standard example code as stated in ipinfo/go.
But I get the following errors:
I am using:
Go Version: go 1.19
Router: Gin (https://github.com/gin-gonic/gin)
Code:
client := ipinfo.NewClient(nil, nil, token)
Error:
too many arguments in call to ipinfo.NewClient
have (nil, nil, string)
want (*http.Client)
And
Code:
info, err := client.GetIPInfo(net.ParseIP(ip_address))
Error:
client.GetIPInfo undefined (type *ipinfo.Client has no field or method GetIPInfo)
The function ipinfo.NewClient takes 1 argument instead of 3.
Is the documentation/readme outdated?
Implement SDK support for IP summaries.
https://ipinfo.io/developers/batch
Take into account use cases like ipinfo/python#35 to ensure batch ops support is scalable & robust.
The link in the About section of the repository points to the godoc for v1.0.0
: https://pkg.go.dev/github.com/ipinfo/go-ipinfo/ipinfo
The new link is: https://pkg.go.dev/github.com/ipinfo/go/v2
Excuse me. Does the library provide region code?
package main
import (
"fmt"
"log"
"net"
"github.com/ipinfoio/go-ipinfo/ipinfo"
)
func main() {
_, err := ipinfo.GetInfo(net.ParseIP("2a03:2880:f10a:83:face:b00c:0:25de"))
if err != nil {
log.Fatal(err)
}
}
$ go run main.go
2017/10/31 14:16:12 parse 2a03:2880:f10a:83:face:b00c:0:25de: first path segment in URL cannot contain colon
exit status 1
According to the guidelines:
The wrapper should send all requests with the following user agent format:
IPinfoClient/Language/Version
For example:
IPinfoClient/Go/1.0
$ go run batch-asn/main.go
doing lookup #0
panic: interface conversion: interface {} is *interface {}, not *ipinfo.ASNDetails
goroutine 1 [running]:
github.com/ipinfo/go/v2/ipinfo.(*Client).GetASNDetailsBatch(0x6efba0, {0xc0000621e0, 0x696c48, 0x11}, {0x127ed0, 0x1, 0x1, 0x70})
/home/petr/go/pkg/mod/github.com/ipinfo/go/[email protected]/ipinfo/batch.go:325 +0x170
main.main()
/home/petr/go/pkg/mod/github.com/ipinfo/go/[email protected]/example/batch-asn/main.go:21 +0x1e5
exit status 2
$ go run batch-core-netip/main.go
doing lookup #0
panic: interface conversion: interface {} is *interface {}, not *ipinfo.Core
goroutine 1 [running]:
github.com/ipinfo/go/v2/ipinfo.(*Client).GetIPStrInfoBatch(0xc0000b2470, {0xc0000d41c0, 0x0, 0x4b1500}, {0x10, 0xc, 0x1, 0x70})
/home/petr/go/pkg/mod/github.com/ipinfo/go/[email protected]/ipinfo/batch.go:294 +0x170
github.com/ipinfo/go/v2/ipinfo.(*Client).GetIPInfoBatch(0x69476b, {0xc0000d1ee0, 0x2, 0x11}, {0xd1ea0, 0x1, 0x1, 0xa0})
/home/petr/go/pkg/mod/github.com/ipinfo/go/[email protected]/ipinfo/batch.go:266 +0xa5
main.main()
/home/petr/go/pkg/mod/github.com/ipinfo/go/[email protected]/example/batch-core-netip/main.go:22 +0x257
exit status 2
$ go run batch-core-str/main.go
doing lookup #0
panic: interface conversion: interface {} is *interface {}, not *ipinfo.Core
goroutine 1 [running]:
github.com/ipinfo/go/v2/ipinfo.(*Client).GetIPStrInfoBatch(0x6efb80, {0xc0000621e0, 0x696c2c, 0x11}, {0x127ed0, 0x1, 0x1, 0x70})
/home/petr/go/pkg/mod/github.com/ipinfo/go/[email protected]/ipinfo/batch.go:294 +0x170
main.main()
/home/petr/go/pkg/mod/github.com/ipinfo/go/[email protected]/example/batch-core-str/main.go:21 +0x1e5
exit status 2
$ go run batch-generic/main.go
doing lookup #0
k=error v=0xc0004ce060
doing lookup #1
k=error v=0xc0004ce1a0
doing lookup #2
k=error v=0xc000091700
Should be ipinfo/go in github, to match our other repos, which are just named after the language
Create a simple function that accepts an IP list (max 500k) and returns the JSON response from https://ipinfo.io/maps
.
We added a package-level isEU function, but that isn't what we really want. We want isEU to be a function on the Core
object so that users can run that on their core objects to get the result.
The GetIPInfoBatch
method does not work, it always creates this error interface conversion: interface {} is *interface {}, not *ipinfo.Core
Example code:
client := ipinfo.NewClient(nil, nil, "<TOKEN>")
batchResult, err := client.GetIPInfoBatch(
[]net.IP{
net.ParseIP("1.1.1.1"),
net.ParseIP("8.8.8.8"),
},
ipinfo.BatchReqOpts{
BatchSize: 10,
TimeoutPerBatch: 0,
TimeoutTotal: 5,
},
)
if err != nil {
fmt.Println(err)
}
fmt.Println(batchResult)
Expected output: IP Info for the batch
Actual output:
panic: interface conversion: interface {} is *interface {}, not *ipinfo.Core
goroutine 1 [running]:
github.com/ipinfo/go/v2/ipinfo.(*Client).GetIPStrInfoBatch(0x140000b6490?, {0x140000cc1c0?, 0x0?, 0x10?}, {0x0, 0x0, 0x5, 0x0, 0x0})
/Users/jc/.gvm/pkgsets/go1.18.1/global/pkg/mod/github.com/ipinfo/go/[email protected]/ipinfo/batch.go:310 +0x17c
github.com/ipinfo/go/v2/ipinfo.(*Client).GetIPInfoBatch(0x100394ccc?, {0x140000c5e48, 0x2, 0x11?}, {0x0, 0x0, 0x5, 0x0, 0x0})
/Users/jc/.gvm/pkgsets/go1.18.1/global/pkg/mod/github.com/ipinfo/go/[email protected]/ipinfo/batch.go:282 +0x8c
main.GenerateIpinfoMap({0x10046b5a0?, 0x140000c5f50?, 0x140000c5f28?})
/Users/jc/Dev/ipinfo_api.go:22 +0x250
main.main()
/Users/jc/Dev/main.go:55 +0xd4
exit status 2
When we send a batch request for X amount of IPs, and X > 1000, we start chunking X into groups of 1000, and make requests for each group separately to the IPinfo batch endpoint, because the endpoint does not accept a size greater than 1000.
However, we do this all at once for all chunks: if there were 500k IPs as input, 500 simultaneous, parallel requests would be made. The issue with this is we may exceed the file descriptor limit of the user; we had this issue with e.g. the CLI.
Implement an upper-limit on the number of simultaneous, parallel requests being made.
Fix go mod path so it has a /v2
at the end so that new module tooling works properly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.