feat: improve compatibility

This commit is contained in:
scientificworld 2023-07-01 22:12:48 +08:00
parent a74d121d88
commit 8e984033dd
No known key found for this signature in database
GPG Key ID: 26E695328487D75E
1 changed files with 8 additions and 2 deletions

View File

@ -12,6 +12,8 @@ import (
"path/filepath"
)
const defaultInputFile = "ip.txt"
func getDefaultInputFile() string {
exe, err := os.Executable()
if err != nil {
@ -21,7 +23,7 @@ func getDefaultInputFile() string {
if err != nil {
log.Fatal(err)
}
return filepath.Dir(sym) + "/ip.txt"
return filepath.Join(filepath.Dir(sym), defaultInputFile)
}
var (
@ -176,7 +178,11 @@ func loadIPRanges() []*net.IPAddr {
}
} else { // 从文件中获取 IP 段数据
if IPFile == "" {
IPFile = getDefaultInputFile()
if _, err := os.Stat(defaultInputFile); err != nil {
IPFile = getDefaultInputFile()
} else {
IPFile = defaultInputFile
}
}
file, err := os.Open(IPFile)
if err != nil {