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!")
|
||||
}
|
||||
|
||||
if err != nil || db == nil {
|
||||
if err != nil {
|
||||
log.Fatalln("Database init failed:", err)
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ func (r CDNResult) String() string {
|
||||
}
|
||||
|
||||
func NewCDN(filePath string) (*CDN, error) {
|
||||
fileData := make([]byte, 0)
|
||||
var fileData []byte
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
log.Println("文件不存在,尝试从网络获取最新CDN数据库")
|
||||
|
@ -1,7 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
@ -46,8 +46,8 @@ func (c *HttpClient) Get(urls ...string) (body []byte, err error) {
|
||||
resp, err = c.Do(req)
|
||||
|
||||
if err == nil && resp != nil && resp.StatusCode == 200 {
|
||||
defer resp.Body.Close()
|
||||
body, err = ioutil.ReadAll(resp.Body)
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@ -10,12 +10,11 @@ import (
|
||||
"github.com/ip2location/ip2location-go/v9"
|
||||
)
|
||||
|
||||
// IP2Location
|
||||
type IP2Location struct {
|
||||
db *ip2location.DB
|
||||
}
|
||||
|
||||
// new IP2Location from database file
|
||||
// NewIP2Location from database file
|
||||
func NewIP2Location(filePath string) (*IP2Location, error) {
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
|
@ -8,8 +8,9 @@ func (db *IPDB[uint32]) SearchIndexV4(ip uint32) uint32 {
|
||||
ipLen := db.IPLen
|
||||
entryLen := uint32(db.OffLen + db.IPLen)
|
||||
|
||||
buf := make([]byte, entryLen)
|
||||
l, r, mid, ipc := db.IdxStart, db.IdxEnd, uint32(0), uint32(0)
|
||||
l, r := db.IdxStart, db.IdxEnd
|
||||
var ipc, mid uint32
|
||||
var buf []byte
|
||||
|
||||
for {
|
||||
mid = (r-l)/entryLen/2*entryLen + l
|
||||
|
@ -39,6 +39,9 @@ const (
|
||||
|
||||
func getData() (data []byte, err error) {
|
||||
data, err = common.GetHttpClient().Get(zx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file7z, err := os.CreateTemp("", "*")
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user