Giter Site home page Giter Site logo

ipinfo / go Goto Github PK

View Code? Open in Web Editor NEW
106.0 16.0 74.0 173 KB

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

Go 99.42% Shell 0.58%
go ipinfo ip-geolocation ip-address ip-data

go's People

Contributors

abdullahdevrel avatar abu-usama avatar ahmadmujahid2k avatar awaismslm avatar deltwalrus avatar harisabdullah avatar przmv avatar rm-umar avatar sobanmahmood avatar st-polina avatar umanshahzad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go's Issues

Add optional IP selection handler

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.

Use versioned cache key

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 install method is deprecated

$ 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'.

Too many arguments in call to ipinfo.NewClient

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?

IPv6 error

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

Change User-Agent string

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

panics and errors when running `batch-*` examples

$ 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

Move to "go" repo

Should be ipinfo/go in github, to match our other repos, which are just named after the language

Map integration

Create a simple function that accepts an IP list (max 500k) and returns the JSON response from https://ipinfo.io/maps.

Create IsEU function on Core object

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.

GetIpInfoBatch: panic: interface conversion: interface {} is *interface {}, not *ipinfo.Core

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

Limit the number of simultaneous batch chunk reqs

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

Fix go mod path so it has a /v2 at the end so that new module tooling works properly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.