package the source lib to xdb

This commit is contained in:
lion 2022-06-17 15:23:02 +08:00
parent be472cbbf7
commit ffb5488988
10 changed files with 28 additions and 27 deletions

12
.gitignore vendored
View File

@ -40,7 +40,7 @@ META-INF/
# golang # golang
/binding/golang/searcher /binding/golang/searcher
/binding/golang/dbsearcher /binding/golang/xdb_searcher
/binding/golang/golang /binding/golang/golang
# rust # rust
@ -50,10 +50,10 @@ target
# VS ignore cases # VS ignore cases
/**/*.sln /**/*.sln
/v1.0//binding/c#/**/.vs/ /v1.0/binding/c#/**/.vs/
/v1.0//binding/c#/**/packages /v1.0/binding/c#/**/packages
/v1.0//binding/c#/**/bin /v1.0/binding/c#/**/bin
/v1.0//binding/c#/**/obj /v1.0/binding/c#/**/obj
/binding/c#/**/.vs/ /binding/c#/**/.vs/
/binding/c#/**/packages /binding/c#/**/packages
/binding/c#/**/bin /binding/c#/**/bin
@ -68,3 +68,5 @@ target
# maker # maker
## golang ## golang
/maker/golang/dbmaker /maker/golang/dbmaker
/maker/golang/xdb_maker
/maker/golang/golang

View File

@ -1,3 +1,3 @@
module dbmaker module github.com/lionsoul2014/ip2region/maker/golang
go 1.17 go 1.17

View File

@ -1,2 +0,0 @@
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=

View File

@ -7,6 +7,7 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/lionsoul2014/ip2region/maker/golang/xdb"
"log" "log"
"os" "os"
"strings" "strings"
@ -25,7 +26,7 @@ func printHelp() {
func genDb() { func genDb() {
var err error var err error
var srcFile, dstFile = "", "" var srcFile, dstFile = "", ""
var indexPolicy = VectorIndexPolicy var indexPolicy = xdb.VectorIndexPolicy
for i := 2; i < len(os.Args); i++ { for i := 2; i < len(os.Args); i++ {
r := os.Args[i] r := os.Args[i]
if len(r) < 5 { if len(r) < 5 {
@ -48,7 +49,7 @@ func genDb() {
case "dst": case "dst":
dstFile = r[eIdx+1:] dstFile = r[eIdx+1:]
case "index": case "index":
indexPolicy, err = IndexPolicyFromString(r[eIdx+1:]) indexPolicy, err = xdb.IndexPolicyFromString(r[eIdx+1:])
if err != nil { if err != nil {
fmt.Printf("parse policy: %s", err.Error()) fmt.Printf("parse policy: %s", err.Error())
return return
@ -66,7 +67,7 @@ func genDb() {
// make the binary file // make the binary file
tStart := time.Now() tStart := time.Now()
maker, err := NewMaker(indexPolicy, srcFile, dstFile) maker, err := xdb.NewMaker(indexPolicy, srcFile, dstFile)
if err != nil { if err != nil {
log.Fatalf("failed to create maker: %s", err) log.Fatalf("failed to create maker: %s", err)
} }
@ -121,7 +122,7 @@ func testSearch() {
return return
} }
searcher, err := NewSearcher(dbFile) searcher, err := xdb.NewSearcher(dbFile)
if err != nil { if err != nil {
log.Fatalf("failed to create searcher: %s", err.Error()) log.Fatalf("failed to create searcher: %s", err.Error())
} }
@ -163,7 +164,7 @@ quit : exit the test program`)
break break
} }
ip, err := CheckIP(line) ip, err := xdb.CheckIP(line)
if err != nil { if err != nil {
fmt.Printf("invalid ip address `%s`\n", line) fmt.Printf("invalid ip address `%s`\n", line)
continue continue
@ -226,7 +227,7 @@ func testBench() {
return return
} }
searcher, err := NewSearcher(dbFile) searcher, err := xdb.NewSearcher(dbFile)
defer func() { defer func() {
searcher.Close() searcher.Close()
}() }()
@ -248,13 +249,13 @@ func testBench() {
return return
} }
sip, err := CheckIP(ps[0]) sip, err := xdb.CheckIP(ps[0])
if err != nil { if err != nil {
fmt.Printf("check start ip `%s`: %s\n", ps[0], err) fmt.Printf("check start ip `%s`: %s\n", ps[0], err)
return return
} }
eip, err := CheckIP(ps[1]) eip, err := xdb.CheckIP(ps[1])
if err != nil { if err != nil {
fmt.Printf("check end ip `%s`: %s\n", ps[1], err) fmt.Printf("check end ip `%s`: %s\n", ps[1], err)
return return
@ -266,12 +267,12 @@ func testBench() {
} }
fmt.Printf("try to bench segment: `%s`\n", l) fmt.Printf("try to bench segment: `%s`\n", l)
mip := MidIP(sip, eip) mip := xdb.MidIP(sip, eip)
for _, ip := range []uint32{sip, MidIP(sip, mip), mip, MidIP(mip, eip), eip} { for _, ip := range []uint32{sip, xdb.MidIP(sip, mip), mip, xdb.MidIP(mip, eip), eip} {
fmt.Printf("|-try to bench ip '%s' ... ", Long2IP(ip)) fmt.Printf("|-try to bench ip '%s' ... ", xdb.Long2IP(ip))
region, _, err := searcher.Search(ip) region, _, err := searcher.Search(ip)
if err != nil { if err != nil {
fmt.Printf("failed to search ip '%s': %s\n", Long2IP(ip), err) fmt.Printf("failed to search ip '%s': %s\n", xdb.Long2IP(ip), err)
return return
} }

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a Apache2.0-style // Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package xdb
import ( import (
"encoding/binary" "encoding/binary"

View File

@ -47,7 +47,7 @@
// +------------+-----------+---------------+------------+ // +------------+-----------+---------------+------------+
// start ip end ip data length data ptr // start ip end ip data length data ptr
package main package xdb
import ( import (
"bufio" "bufio"

View File

@ -8,7 +8,7 @@
// please use the searcher in binding/golang for production use. // please use the searcher in binding/golang for production use.
// And this is a Not thread safe implementation. // And this is a Not thread safe implementation.
package main package xdb
import ( import (
"encoding/binary" "encoding/binary"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a Apache2.0-style // Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package xdb
import ( import (
"fmt" "fmt"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a Apache2.0-style // Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package xdb
import ( import (
"encoding/binary" "encoding/binary"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a Apache2.0-style // Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package xdb
import ( import (
"fmt" "fmt"