Skip to content

Commit

Permalink
chore: make code scanning happy
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Aug 24, 2023
1 parent 07409ff commit 6462935
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/db/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cdn/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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数据库")
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/httpclient.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package common

import (
"io/ioutil"
"io"
"log"
"net/http"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/ip2location/ip2location.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/wry/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/zxipv6wry/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6462935

Please sign in to comment.