-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from ipinfo/uman/batch-ops
Batch ops
- Loading branch information
Showing
11 changed files
with
572 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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.GetASNDetailsBatch( | ||
[]string{ | ||
"AS321", | ||
"AS999", | ||
}, | ||
ipinfo.BatchReqOpts{ | ||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
"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.GetIPInfoBatch( | ||
[]net.IP{ | ||
net.ParseIP("1.1.1.1"), | ||
net.ParseIP("8.8.8.8"), | ||
}, | ||
ipinfo.BatchReqOpts{ | ||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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.GetIPStrInfoBatch( | ||
[]string{ | ||
"1.1.1.1", | ||
"8.8.8.8", | ||
}, | ||
ipinfo.BatchReqOpts{ | ||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= | ||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= | ||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= | ||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.