-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (40 loc) · 725 Bytes
/
main.go
File metadata and controls
43 lines (40 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/ipinfo/go/v2/ipinfo"
"github.com/ipinfo/go/v2/ipinfo/cache"
)
func main() {
client := ipinfo.NewClient(
nil,
ipinfo.NewCache(cache.NewInMemory().WithExpiration(5*time.Minute)),
os.Getenv("TOKEN"),
)
for i := 0; i < 3; i++ {
fmt.Printf("doing lookup #%v\n", i)
batchResult, err := client.GetBatch(
[]string{
"1.1.1.1",
"1.1.1.1/country",
"8.8.8.8",
"8.8.8.8/country",
"AS321",
},
ipinfo.BatchReqOpts{
BatchSize: 2,
TimeoutPerBatch: 0,
TimeoutTotal: 5,
},
)
if err != nil {
log.Fatal(err)
}
for k, v := range batchResult {
fmt.Printf("k=%v v=%v\n", k, v)
}
fmt.Println()
}
}