判断配置文件是否存在

This commit is contained in:
aixiao 2023-12-28 10:35:13 +08:00
parent 41293c6d47
commit 01f4d175a0
5 changed files with 26 additions and 3 deletions

25
main.go
View File

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"time" "time"
@ -98,12 +99,34 @@ func SubProcess(args []string) *exec.Cmd {
return cmd return cmd
} }
func get_ini() string {
exePath, err := os.Executable()
if err != nil {
fmt.Println("无法获取可执行文件路径:", err)
return ""
}
exeDir := filepath.Dir(exePath)
exeDir = filepath.Join(exeDir, "public_ip.ini")
fmt.Println(exeDir)
return exeDir
}
func main() { func main() {
var version = "1.0.0" var version = "1.0.0"
// 获取当前可执行文件的路径
INI_FILE := get_ini()
_, err := os.Stat(INI_FILE)
if os.IsNotExist(err) {
fmt.Println("配置文件不存在")
os.Exit(0)
}
// 读取配置文件 // 读取配置文件
cfgs, err := ini.Load("public_ip.ini") cfgs, err := ini.Load(INI_FILE)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }

BIN
public_ip

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -9,5 +9,5 @@ SedIpURL="http://58.34.44.125:6108/ip/set/ip?ip=%s&storeNo=%s"
StoreNo=2 StoreNo=2
# 等待时间 # 等待时间
While_Time=20 While_Time=60