mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
chore: make code scanning happy
This commit is contained in:
parent
07409ff628
commit
6462935b1b
@ -53,7 +53,7 @@ func (d *DB) get() (db dbif.DB) {
|
|||||||
panic("DB format not supported!")
|
panic("DB format not supported!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil || db == nil {
|
if err != nil {
|
||||||
log.Fatalln("Database init failed:", err)
|
log.Fatalln("Database init failed:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func (r CDNResult) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCDN(filePath string) (*CDN, error) {
|
func NewCDN(filePath string) (*CDN, error) {
|
||||||
fileData := make([]byte, 0)
|
var fileData []byte
|
||||||
_, err := os.Stat(filePath)
|
_, err := os.Stat(filePath)
|
||||||
if err != nil && os.IsNotExist(err) {
|
if err != nil && os.IsNotExist(err) {
|
||||||
log.Println("文件不存在,尝试从网络获取最新CDN数据库")
|
log.Println("文件不存在,尝试从网络获取最新CDN数据库")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -46,8 +46,8 @@ func (c *HttpClient) Get(urls ...string) (body []byte, err error) {
|
|||||||
resp, err = c.Do(req)
|
resp, err = c.Do(req)
|
||||||
|
|
||||||
if err == nil && resp != nil && resp.StatusCode == 200 {
|
if err == nil && resp != nil && resp.StatusCode == 200 {
|
||||||
defer resp.Body.Close()
|
body, err = io.ReadAll(resp.Body)
|
||||||
body, err = ioutil.ReadAll(resp.Body)
|
_ = resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,11 @@ import (
|
|||||||
"github.com/ip2location/ip2location-go/v9"
|
"github.com/ip2location/ip2location-go/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IP2Location
|
|
||||||
type IP2Location struct {
|
type IP2Location struct {
|
||||||
db *ip2location.DB
|
db *ip2location.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// new IP2Location from database file
|
// NewIP2Location from database file
|
||||||
func NewIP2Location(filePath string) (*IP2Location, error) {
|
func NewIP2Location(filePath string) (*IP2Location, error) {
|
||||||
_, err := os.Stat(filePath)
|
_, err := os.Stat(filePath)
|
||||||
if err != nil && os.IsNotExist(err) {
|
if err != nil && os.IsNotExist(err) {
|
||||||
|
@ -8,8 +8,9 @@ func (db *IPDB[uint32]) SearchIndexV4(ip uint32) uint32 {
|
|||||||
ipLen := db.IPLen
|
ipLen := db.IPLen
|
||||||
entryLen := uint32(db.OffLen + db.IPLen)
|
entryLen := uint32(db.OffLen + db.IPLen)
|
||||||
|
|
||||||
buf := make([]byte, entryLen)
|
l, r := db.IdxStart, db.IdxEnd
|
||||||
l, r, mid, ipc := db.IdxStart, db.IdxEnd, uint32(0), uint32(0)
|
var ipc, mid uint32
|
||||||
|
var buf []byte
|
||||||
|
|
||||||
for {
|
for {
|
||||||
mid = (r-l)/entryLen/2*entryLen + l
|
mid = (r-l)/entryLen/2*entryLen + l
|
||||||
|
@ -39,6 +39,9 @@ const (
|
|||||||
|
|
||||||
func getData() (data []byte, err error) {
|
func getData() (data []byte, err error) {
|
||||||
data, err = common.GetHttpClient().Get(zx)
|
data, err = common.GetHttpClient().Get(zx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
file7z, err := os.CreateTemp("", "*")
|
file7z, err := os.CreateTemp("", "*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user