feat: geo ip.

This commit is contained in:
tx7do
2023-10-19 15:27:32 +08:00
parent 01bdf5cc06
commit 7965576c1c
8 changed files with 73 additions and 34 deletions

View File

@@ -3,11 +3,14 @@ package qqwry
import (
"bytes"
"io"
"regexp"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
var regSpiltAddress = regexp.MustCompile(`.+?(省|市|自治区|自治州|盟|县|区|管委会|街道|镇|乡)`)
func gb18030Decode(src []byte) string {
in := bytes.NewReader(src)
out := transform.NewReader(in, simplifiedchinese.GB18030.NewDecoder())
@@ -26,3 +29,7 @@ func byte3ToUInt32(data []byte) uint32 {
i |= (uint32(data[2]) << 16) & 0xff0000
return i
}
func SpiltAddress(addr string) []string {
return regSpiltAddress.FindAllString(addr, -1)
}