Update the docs
This commit is contained in:
parent
4cf2c28d49
commit
98e10b9891
|
|
@ -7,7 +7,7 @@
|
||||||
go get github.com/lionsoul2014/ip2region/binding/golang
|
go get github.com/lionsoul2014/ip2region/binding/golang
|
||||||
```
|
```
|
||||||
|
|
||||||
### API 使用
|
### API 使用 Demo
|
||||||
```golang
|
```golang
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -40,6 +40,49 @@ func main() {
|
||||||
|
|
||||||
# 编译测试程序
|
# 编译测试程序
|
||||||
|
|
||||||
|
通过如下方式编译得到 searcher 可执行程序:
|
||||||
|
```bash
|
||||||
|
# 切换到 golang binding 根目录
|
||||||
|
go build -o searcher
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# 查询测试
|
# 查询测试
|
||||||
|
|
||||||
|
通过 `searcher search` 命令来测试 ip2region.xdb 的查询:
|
||||||
|
```
|
||||||
|
➜ golang git:(v2.0_xdb) ✗ ./searcher search
|
||||||
|
dbmaker test [command options]
|
||||||
|
options:
|
||||||
|
--db string ip2region binary xdb file path
|
||||||
|
```
|
||||||
|
|
||||||
|
例如:使用默认的 data/ip2region.xdb 进行查询测试
|
||||||
|
```bash
|
||||||
|
➜ golang git:(v2.0_xdb) ✗ ./searcher search --db=../../data/ip2region.xdb
|
||||||
|
ip2region 2.0 searcher test program, type `quit` to exit
|
||||||
|
ip2region>> 1.2.3.4
|
||||||
|
{region:美国|0|华盛顿|0|谷歌, took:101.57µs}
|
||||||
|
```
|
||||||
|
|
||||||
|
输入 ip 地址进行查询即可,输入 quit 退出测试程序。
|
||||||
|
|
||||||
|
|
||||||
# bench 测试
|
# bench 测试
|
||||||
|
|
||||||
|
通过 `searcher bench` 命令来进行自动 bench 测试,一方便得到大量查询的效率,一方便确保程序和xdb文件都没有错误:
|
||||||
|
```bash
|
||||||
|
➜ golang git:(v2.0_xdb) ✗ ./searcher bench
|
||||||
|
searcher bench [command options]
|
||||||
|
options:
|
||||||
|
--db string ip2region binary xdb file path
|
||||||
|
--src string source ip text file path
|
||||||
|
```
|
||||||
|
|
||||||
|
例如:通过 data/ip2region.xdb 和 data/ip.merge.txt 进行 bench 测试:
|
||||||
|
```bash
|
||||||
|
➜ golang git:(v2.0_xdb) ✗ ./searcher bench --db=../../data/ip2region.xdb --src=../../data/ip.merge.txt
|
||||||
|
Bench finished, {total: 3417955, took: 28.211578339s, cost: 8253 ns/op}
|
||||||
|
```
|
||||||
|
|
||||||
|
bench 程序会逐行读取 `src` 指定的源IP文件,然后每个 IP 段选取 5 个固定位置的 IP 进行测试,以确保查询的 region 信息和原始的 region 信息是相同。测试途中没有调试信息的输出,有错误会打印错误信息并且终止运行,所以看到 `Bench finished` 就表示 bench 成功了,cost 是表示每次查询操作的平均时间(ns)。
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
通过如下方式编译得到 dbmaker 可执行程序:
|
通过如下方式编译得到 dbmaker 可执行程序:
|
||||||
```
|
```
|
||||||
# 切换到golang maker 根目录
|
# 切换到golang maker 根目录
|
||||||
cd ./
|
|
||||||
go build
|
go build
|
||||||
```
|
```
|
||||||
编译成功后会在当前目录生成一个 dbmaker 的可执行文件
|
编译成功后会在当前目录生成一个 dbmaker 的可执行文件
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue