Merge pull request #447 from lionsoul2014/i18n_golang_maker_readme

I18n golang maker readme
This commit is contained in:
Leon / 狮子的魂 2026-02-25 22:46:43 +08:00 committed by GitHub
commit 832e3fd77d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 196 additions and 37 deletions

View File

@ -67,12 +67,12 @@ For API introductions, usage documentation, and test programs, please refer to t
| Language | Description | IPv4 Support | IPv6 Support | | Language | Description | IPv4 Support | IPv6 Support |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| [Golang](maker/golang) | golang xdb generation program | :white_check_mark: | :white_check_mark: | | [Golang](maker/golang/README.md) | golang xdb generation program | :white_check_mark: | :white_check_mark: |
| [Java](maker/java) | java xdb generation program | :white_check_mark: | :white_check_mark: | | [Java](maker/java) | java xdb generation program | :white_check_mark: | :white_check_mark: |
| [Python](maker/python) | python xdb generation program | :white_check_mark: | :x: | | [Python](maker/python) | python xdb generation program | :white_check_mark: | :x: |
| [Csharp](maker/csharp) | csharp xdb generation program | :white_check_mark: | :x: | | [Csharp](maker/csharp) | csharp xdb generation program | :white_check_mark: | :x: |
| [Rust](maker/rust) | rust xdb generation program | :white_check_mark: | :white_check_mark: | | [Rust](maker/rust) | rust xdb generation program | :white_check_mark: | :white_check_mark: |
| [C++](maker/cpp) | C++ xdb generation program | :white_check_mark: | :white_check_mark: | | [C++](maker/cpp) | C++ xdb generation program | :white_check_mark: | :white_check_mark: |
# `xdb` Update # `xdb` Update

View File

@ -66,12 +66,12 @@ API 介绍,使用文档和测试程序请参考如下 `maker` 生成程序下
| 编程语言 | 描述 | IPv4 支持 | IPv6 支持 | | 编程语言 | 描述 | IPv4 支持 | IPv6 支持 |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| [Golang](maker/golang) | golang xdb 生成程序 | :white_check_mark: | :white_check_mark: | | [Golang](maker/golang/README_zh.md) | golang xdb 生成程序 | :white_check_mark: | :white_check_mark: |
| [Java](maker/java) | java xdb 生成程序 | :white_check_mark: | :white_check_mark: | | [Java](maker/java) | java xdb 生成程序 | :white_check_mark: | :white_check_mark: |
| [Python](maker/python) | python xdb 生成程序 | :white_check_mark: | :x: | | [Python](maker/python) | python xdb 生成程序 | :white_check_mark: | :x: |
| [Csharp](maker/csharp) | csharp xdb 生成程序 | :white_check_mark: | :x: | | [Csharp](maker/csharp) | csharp xdb 生成程序 | :white_check_mark: | :x: |
| [Rust](maker/rust) | rust xdb 生成程序 | :white_check_mark: | :white_check_mark: | | [Rust](maker/rust) | rust xdb 生成程序 | :white_check_mark: | :white_check_mark: |
| [C++](maker/cpp) | C++ xdb 生成程序 | :white_check_mark: | :white_check_mark: | | [C++](maker/cpp) | C++ xdb 生成程序 | :white_check_mark: | :white_check_mark: |
# `xdb` 更新 # `xdb` 更新

View File

@ -1,19 +1,22 @@
# ip2region xdb golang 生成实现 :globe_with_meridians: [中文简体](README_zh.md) | [English](README.md)
# ip2region xdb golang generation implementation
# 程序编译 # Program Compilation
Compile to get the xdb_maker executable through the following method:
通过如下方式编译得到 xdb_maker 可执行程序:
``` ```
# 切换到golang maker 根目录 # cd to the golang maker root directory
make make
``` ```
编译成功后会在当前目录生成一个 xdb_maker 的可执行文件
After successful compilation, a xdb_maker executable file will be generated in the current directory.
# `xdb` 数据生成 # `xdb` Data Generation
Generate the ip2region.xdb binary file via the `xdb_maker gen` command:
通过 `xdb_maker gen` 命令生成 ip2region.xdb 二进制文件:
``` ```
./xdb_maker gen [command options] ./xdb_maker gen [command options]
options: options:
@ -24,7 +27,8 @@ options:
--log-level string set the log level, options: debug/info/warn/error --log-level string set the log level, options: debug/info/warn/error
``` ```
例如,使用默认的仓库 data/ 下默认的原始数据生成生成 xdb 文件到当前目录: For example, generate the xdb file to the current directory using the default source data under the repository's data/ directory:
```bash ```bash
# ipv4 # ipv4
./xdb_maker gen --src=../../data/ipv4_source.txt --dst=./ip2region_v4.xdb --version=ipv4 ./xdb_maker gen --src=../../data/ipv4_source.txt --dst=./ip2region_v4.xdb --version=ipv4
@ -32,12 +36,12 @@ options:
./xdb_maker gen --src=../../data/ipv6_source.txt --dst=./ip2region_v6.xdb --version=ipv6 ./xdb_maker gen --src=../../data/ipv6_source.txt --dst=./ip2region_v6.xdb --version=ipv6
``` ```
生成过程中数据字段自定义请参考 [xdb-文件生成#自定义数据字段](https://ip2region.net/doc/data/xdb_make#field-list) For custom data fields during the generation process, please refer to [xdb-文件生成#自定义数据字段](https://ip2region.net/doc/data/xdb_make#field-list)
# `xdb` Data Search
# `xdb` 数据查询 Test the input IP via the `xdb_maker search` command:
通过 `xdb_maker search` 命令来测试查询输入的 ip
``` ```
➜ golang git:(v2.0_xdb) ✗ ./xdb_maker search ➜ golang git:(v2.0_xdb) ✗ ./xdb_maker search
./xdb_maker search [command options] ./xdb_maker search [command options]
@ -45,7 +49,8 @@ options:
--db string ip2region binary xdb file path --db string ip2region binary xdb file path
``` ```
例如,使用自带的 xdb 文件来运行查询测试: For example, run a search test using the built-in xdb file:
```bash ```bash
# ipv4 # ipv4
./xdb_maker search --db=../../data/ip2region_v4.xdb ./xdb_maker search --db=../../data/ip2region_v4.xdb
@ -71,12 +76,13 @@ commands:
ip2region>> 2604:bc80:8001:11a4:ffff:ffff:ffff:ffff ip2region>> 2604:bc80:8001:11a4:ffff:ffff:ffff:ffff
{region:United States|Florida|Miami|velia.net Internetdienste GmbH|US, iocount:15, took:140.942µs} {region:United States|Florida|Miami|velia.net Internetdienste GmbH|US, iocount:15, took:140.942µs}
ip2region>> 240e:3b7:3273:51d0:13f9:bf0:3db1:aa3f ip2region>> 240e:3b7:3273:51d0:13f9:bf0:3db1:aa3f
{region:中国|广东省|深圳市|电信|CN, iocount:9, took:67.058µs} {region:中国|广东省|深圳市|电信|CN, iocount:9, took:67058µs}
``` ```
# `xdb` 数据编辑 # `xdb` Data Editing
Edit the raw IP data via the `xdb_maker edit` command:
通过 `xdb_maker edit` 命令来编辑原始的 IP 数据:
``` ```
./xdb_maker edit [command options] ./xdb_maker edit [command options]
options: options:
@ -84,7 +90,8 @@ options:
--version string IP version, options: ipv4/ipv6, specify this flag so you don't get confused --version string IP version, options: ipv4/ipv6, specify this flag so you don't get confused
``` ```
例如,使用编辑器打开 `./data/ipv4_source.txt` 会看到如下的操作面板: For example, opening `./data/ipv4_source.txt` with the editor will show the following operation panel:
```bash ```bash
./xdb_maker edit --src=../../data/ipv4_source.txt --version=ipv4 ./xdb_maker edit --src=../../data/ipv4_source.txt --version=ipv4
init the editor from source @ `../../data/ipv4_source.txt` ... init the editor from source @ `../../data/ipv4_source.txt` ...
@ -99,30 +106,34 @@ command list:
editor>> editor>>
``` ```
通过 `put` 命令修改指定 IP 段的定位信息,例如: Modify the location information of a specified IP segment using the `put` command, for example:
```bash ```bash
editor>> put 36.132.128.0|36.132.147.255|中国|黑龙江省|哈尔滨市|移动|CN editor>> put 36.132.128.0|36.132.147.255|中国|黑龙江省|哈尔滨市|移动|CN
Put(36.132.128.0|36.132.147.255|中国|黑龙江省|哈尔滨市|移动): Ok, with 1 deletes and 2 additions Put(36.132.128.0|36.132.147.255|中国|黑龙江省|哈尔滨市|移动|CN): Ok, with 1 deletes and 2 additions
*editor>> *editor>>
``` ```
通过 `put_file` 命令从文件中批量载入修改,文件中的 IP 段不需要像 ./data/ip.merge.txt 中的数据那么严格,不需要前后连续,不同 IP 段有重叠也没关系编辑器会自动分析处理例如 Batch load modifications from a file using the `put_file` command. The IP segments in the file do not need to be as strict as the data in `./data/ipvx_source.txt`; they do not need to be continuous, and it does not matter if different IP segments overlap. The editor will automatically analyze and process them, for example:
```bash ```bash
*editor>> put_file ../../data/ip.test.txt *editor>> put_file ../../data/ip.test.txt
PutFile(../../data/ip.test.txt): Ok, with 25 deletes and 25 additions PutFile(../../data/ip.test.txt): Ok, with 25 deletes and 25 additions
*editor>> *editor>>
``` ```
通过 `save` 命令保存修改,保存成功后,再通过上面的命令从修改后的原始 IP 文件重新生成 xdb 即可: Save modifications using the `save` command. After saving successfully, you can re-generate the xdb from the modified raw IP file using the commands mentioned above:
```bash ```bash
*editor>> save *editor>> save
all segments saved to ../../data/ip.merge.txt all segments saved to ../../data/ip.merge.txt
editor>> editor>>
``` ```
# bench 测试 # bench Test
If you have generated the `xdb` file yourself, please ensure you run the following `xdb_maker bench` command to verify the correctness of the generated `xdb` file:
如果你自主生成了 `xdb` 文件,请确保运行如下的 `xdb_maker bench` 命令来确保生成的的 `xdb` 文件的正确性:
``` ```
./xdb_maker bench [command options] ./xdb_maker bench [command options]
options: options:
@ -133,7 +144,8 @@ options:
--ignore-error bool keep going if bench failed --ignore-error bool keep going if bench failed
``` ```
例如:使用 data 下的源文件来 bench 测试 data 的 xdb 文件: For example: use the source files under data to bench test the xdb files in data:
```bash ```bash
# ipv4 # ipv4
./xdb_maker bench --db=../../data/ip2region_v4.xdb --src=../../data/ipv4_source.txt --version=ipv4 ./xdb_maker bench --db=../../data/ip2region_v4.xdb --src=../../data/ipv4_source.txt --version=ipv4
@ -141,5 +153,6 @@ options:
#ipv6 #ipv6
./xdb_maker bench --db=../../data/ip2region_v6.xdb --src=../../data/ipv6_source.txt --version=ipv6 ./xdb_maker bench --db=../../data/ip2region_v6.xdb --src=../../data/ipv6_source.txt --version=ipv6
``` ```
*请注意 bench 测试使用的 `src` 文件需要是对应的生成 xdb 的源文件相同*。
如果运行过程中有错误会立马停止运行,也可以执行 --ignore-error=true 参数来忽略错误,在最后看 failed 的统计结果。 *Please note that the `src` file used for the bench test must be the same as the source file used to generate the xdb*.
If an error occurs during execution, it will stop immediately. You can also execute with the `--ignore-error=true` parameter to ignore errors and view the failed statistics at the end.

146
maker/golang/README_zh.md Normal file
View File

@ -0,0 +1,146 @@
:globe_with_meridians: [中文简体](README_zh.md) | [English](README.md)
# ip2region xdb golang 生成实现
# 程序编译
通过如下方式编译得到 xdb_maker 可执行程序:
```
# 切换到golang maker 根目录
make
```
编译成功后会在当前目录生成一个 xdb_maker 的可执行文件
# `xdb` 数据生成
通过 `xdb_maker gen` 命令生成 ip2region.xdb 二进制文件:
```
./xdb_maker gen [command options]
options:
--src string source ip text file path
--dst string destination binary xdb file path
--version string IP version, options: ipv4/ipv6, specify this flag so you don't get confused
--field-list string field index list imploded with ',' eg: 0,1,2,3-6,7
--log-level string set the log level, options: debug/info/warn/error
```
例如,使用默认的仓库 data/ 下默认的原始数据生成生成 xdb 文件到当前目录:
```bash
# ipv4
./xdb_maker gen --src=../../data/ipv4_source.txt --dst=./ip2region_v4.xdb --version=ipv4
# ipv6
./xdb_maker gen --src=../../data/ipv6_source.txt --dst=./ip2region_v6.xdb --version=ipv6
```
生成过程中数据字段自定义请参考 [xdb-文件生成#自定义数据字段](https://ip2region.net/doc/data/xdb_make#field-list)
# `xdb` 数据查询
通过 `xdb_maker search` 命令来测试查询输入的 ip
```
➜ golang git:(v2.0_xdb) ✗ ./xdb_maker search
./xdb_maker search [command options]
options:
--db string ip2region binary xdb file path
```
例如,使用自带的 xdb 文件来运行查询测试:
```bash
# ipv4
./xdb_maker search --db=../../data/ip2region_v4.xdb
ip2region xdb search test program,
source xdb: ../../data/ip2region_v4.xdb (IPv4)
commands:
loadIndex : load the vector index for search speedup.
clearIndex: clear the vector index.
quit : exit the test program
ip2region>> 58.251.30.115
{region:中国|广东省|深圳市|联通|CN, iocount:2, took:27.893µs}
ip2region>> 1.2.3.4
{region:Australia|Queensland|Brisbane|0|AU, iocount:5, took:58.746µs}
# ipv6
./xdb_maker search --db=../../data/ip2region_v6.xdb
ip2region xdb search test program,
source xdb: ../../data/ip2region_v6.xdb (IPv6)
commands:
loadIndex : load the vector index for search speedup.
clearIndex: clear the vector index.
quit : exit the test program
ip2region>> 2604:bc80:8001:11a4:ffff:ffff:ffff:ffff
{region:United States|Florida|Miami|velia.net Internetdienste GmbH|US, iocount:15, took:140.942µs}
ip2region>> 240e:3b7:3273:51d0:13f9:bf0:3db1:aa3f
{region:中国|广东省|深圳市|电信|CN, iocount:9, took:67.058µs}
```
# `xdb` 数据编辑
通过 `xdb_maker edit` 命令来编辑原始的 IP 数据:
```
./xdb_maker edit [command options]
options:
--src string source ip text file path
--version string IP version, options: ipv4/ipv6, specify this flag so you don't get confused
```
例如,使用编辑器打开 `./data/ipv4_source.txt` 会看到如下的操作面板:
```bash
./xdb_maker edit --src=../../data/ipv4_source.txt --version=ipv4
init the editor from source @ `../../data/ipv4_source.txt` ...
all segments loaded, length: 683591, elapsed: 479.73743ms
command list:
put [segment] : put the specifield $segment
put_file [file] : put all the segments from the specified $file
list [offset] [size] : list the first $size segments start from $offset
save : save all the changes to the destination source file
quit : exit the program
help : print this help menu
editor>>
```
通过 `put` 命令修改指定 IP 段的定位信息,例如:
```bash
editor>> put 36.132.128.0|36.132.147.255|中国|黑龙江省|哈尔滨市|移动|CN
Put(36.132.128.0|36.132.147.255|中国|黑龙江省|哈尔滨市|移动): Ok, with 1 deletes and 2 additions
*editor>>
```
通过 `put_file` 命令从文件中批量载入修改,文件中的 IP 段不需要像 ./data/ip.merge.txt 中的数据那么严格,不需要前后连续,不同 IP 段有重叠也没关系编辑器会自动分析处理例如
```bash
*editor>> put_file ../../data/ip.test.txt
PutFile(../../data/ip.test.txt): Ok, with 25 deletes and 25 additions
*editor>>
```
通过 `save` 命令保存修改,保存成功后,再通过上面的命令从修改后的原始 IP 文件重新生成 xdb 即可:
```bash
*editor>> save
all segments saved to ../../data/ip.merge.txt
editor>>
```
# bench 测试
如果你自主生成了 `xdb` 文件,请确保运行如下的 `xdb_maker bench` 命令来确保生成的的 `xdb` 文件的正确性:
```
./xdb_maker bench [command options]
options:
--db string ip2region binary xdb file path
--src string source ip text file path
--version string IP version, options: ipv4/ipv6, specify this flag so you don't get confused
--log-level string set the log level, options: debug/info/warn/error
--ignore-error bool keep going if bench failed
```
例如:使用 data 下的源文件来 bench 测试 data 的 xdb 文件:
```bash
# ipv4
./xdb_maker bench --db=../../data/ip2region_v4.xdb --src=../../data/ipv4_source.txt --version=ipv4
#ipv6
./xdb_maker bench --db=../../data/ip2region_v6.xdb --src=../../data/ipv6_source.txt --version=ipv6
```
*请注意 bench 测试使用的 `src` 文件需要是对应的生成 xdb 的源文件相同*。
如果运行过程中有错误会立马停止运行,也可以执行 --ignore-error=true 参数来忽略错误,在最后看 failed 的统计结果。