Files
jh-zz/main.go

69 lines
1.2 KiB
Go

package main
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"slices"
"zzman/actions"
"zzman/clients"
"zzman/model"
"github.com/joho/godotenv"
)
func main() {
// 初始化环境
slog.Debug("初始化环境变量")
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath := filepath.Dir(ex)
file := filepath.Join(exPath, ".env")
println("加载环境变量文件:", file)
err = godotenv.Load(file)
if err != nil {
slog.Error(fmt.Errorf("初始化变量失败:%w", err).Error())
}
model.Init()
clients.InitRedis()
// 执行命令
if len(os.Args) < 2 {
println("缺少命令参数")
return
}
switch {
case os.Args[1] == "sync":
err := actions.Sync()
if err != nil {
slog.Error(fmt.Sprintf("同步城市节点数据失败:%s", err.Error()))
} else {
slog.Info("同步城市节点数据成功")
}
return
case os.Args[1] == "update":
var args actions.UpdateArgs
if len(os.Args) >= 3 {
if slices.Contains(os.Args, "--mock") {
args.Mock = true
}
}
err := actions.Update(model.DB, args)
if err != nil {
slog.Error(fmt.Sprintf("更新节点失败:%s", err.Error()))
} else {
slog.Info("更新节点成功")
}
}
println("请输入正确的命令参数")
}