Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golang实现 #4

Merged
merged 2 commits into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions binding/golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
golang 实现ip地址查询

获取

```
go get github.com/mohong122/ip2region/binding/golang
```




使用

```golang

package main

import (
"fmt"
"github.com/mohong122/ip2region/binding/golang"
)

func main() {
fmt.Println("err")
region, err := ip2region.New("ip2region.db")
defer region.Close()
if err != nil {
fmt.Println(err)
return
}
ip, err := region.MemorySearch("127.0.0.1")
fmt.Println(ip, err)
ip, err = region.BinarySearch("127.0.0.1")
fmt.Println(ip, err)
ip, err = region.BtreeSearch("127.0.0.1")
fmt.Println(ip, err)
}

```

返回对象
```golang
type IpInfo struct {
CityId int64
Country string
Region string
Province string
City string
ISP string
}
```

性能

|名称|次数|平均耗时|
|---|---|------|
BenchmarkBtreeSearch-4| 200000 | 7715 ns/op
BenchmarkMemorySearch-4| 2000000 | 840 ns/op
BenchmarkBinarySearch-4| 30000 | 42680 ns/op

Loading