update ip2region
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.12
李光春 2 years ago
parent f31ee74c5d
commit f6ec861b71

@ -8,7 +8,7 @@ import (
"strings"
)
const Version = "1.0.11"
const Version = "1.0.12"
type App struct {
V4Region ip2region.Ip2Region // IPV4

@ -8,8 +8,9 @@ import (
var app App
func TestOnlineDownload(t *testing.T) {
//t.Log(app.V4db.OnlineDownload()) // 在线下载ipv4数据库
//t.Log(app.V6db.OnlineDownload()) // 在线下载ipv6数据库
//t.Log(app.V4db.OnlineDownload()) // 在线下载ipv4数据库
//t.Log(app.V6db.OnlineDownload()) // 在线下载ipv6数据库
//t.Log(app.V4Region.OnlineDownload()) // 在线下载ip2region数据库
}
func TestIp(t *testing.T) {

@ -0,0 +1,17 @@
package ip2region
import (
"io/ioutil"
"net/http"
)
func getOnline() ([]byte, error) {
resp, err := http.Get("https://ghproxy.com/?q=https://github.com/lionsoul2014/ip2region/blob/master/data/ip2region.db?raw=true")
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
return body, err
}

Binary file not shown.

@ -4,6 +4,8 @@ import (
_ "embed"
"errors"
"go.dtapp.net/gostring"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
@ -160,3 +162,16 @@ func ip2long(IpStr string) (int64, error) {
return sum, nil
}
func (r *Ip2Region) OnlineDownload() (err error) {
tmpData, err := getOnline()
if err != nil {
return errors.New("下载失败 %s" + err.Error())
}
if err := ioutil.WriteFile("./ip2region.db", tmpData, 0644); err == nil {
log.Printf("已下载最新 ip2region 数据库 %s ", "./ip2region.db")
} else {
return errors.New("保存失败")
}
return nil
}

Loading…
Cancel
Save