diff --git a/actions/changes.go b/actions/changes.go index 6b25a68..74e8590 100644 --- a/actions/changes.go +++ b/actions/changes.go @@ -1,7 +1,7 @@ package actions import ( - "zzman/model" + "jhman/model" "gorm.io/gorm" ) diff --git a/actions/cities.go b/actions/cities.go index 2822584..6884024 100644 --- a/actions/cities.go +++ b/actions/cities.go @@ -2,7 +2,7 @@ package actions import ( "fmt" - "zzman/model" + "jhman/model" "gorm.io/gorm" ) diff --git a/actions/clear.go b/actions/clear.go index e184312..1c6606d 100644 --- a/actions/clear.go +++ b/actions/clear.go @@ -2,8 +2,8 @@ package actions import ( "fmt" - "zzman/clients/jd" - "zzman/model" + "jhman/clients/jd" + "jhman/model" ) func Clear() error { diff --git a/actions/configs.go b/actions/configs.go index bbb54ec..77f87c2 100644 --- a/actions/configs.go +++ b/actions/configs.go @@ -1,7 +1,7 @@ package actions import ( - "zzman/model" + "jhman/model" "gorm.io/gorm" ) diff --git a/actions/edges.go b/actions/edges.go index fea4c8b..962037a 100644 --- a/actions/edges.go +++ b/actions/edges.go @@ -2,7 +2,7 @@ package actions import ( "fmt" - "zzman/model" + "jhman/model" "gorm.io/gorm" ) @@ -81,7 +81,7 @@ func SaveEdges(tx *gorm.DB, edges []model.Edge) error { updateQuery := fmt.Sprintf(` UPDATE edge e JOIN %s te ON e.id = te.id - SET + SET e.macaddr = te.macaddr, e.public = te.public, e.isp = te.isp, diff --git a/actions/gateways.go b/actions/gateways.go index e964560..55cee13 100644 --- a/actions/gateways.go +++ b/actions/gateways.go @@ -2,8 +2,8 @@ package actions import ( "fmt" + "jhman/model" "math" - "zzman/model" "gorm.io/gorm" ) diff --git a/actions/gen.go b/actions/gen.go index 4188f05..2e85e03 100644 --- a/actions/gen.go +++ b/actions/gen.go @@ -2,10 +2,10 @@ package actions import ( "fmt" + "jhman/model" "strconv" - "zzman/model" - u "zzman/util" + u "jhman/util" "gorm.io/gorm" ) diff --git a/actions/submit.go b/actions/submit.go index 40a0a9a..1119c05 100644 --- a/actions/submit.go +++ b/actions/submit.go @@ -3,9 +3,9 @@ package actions import ( "encoding/json" "fmt" + "jhman/clients/jd" + "jhman/model" "time" - "zzman/clients/jd" - "zzman/model" ) func RecordSubmit(time time.Time, gatewat model.Gateway, edges []jd.EdgeInfo) error { diff --git a/actions/sync.go b/actions/sync.go index 8f62b0b..abf8ad6 100644 --- a/actions/sync.go +++ b/actions/sync.go @@ -2,9 +2,9 @@ package actions import ( "fmt" + "jhman/clients/jd" + "jhman/model" "log/slog" - "zzman/clients/jd" - "zzman/model" "gorm.io/gorm" ) diff --git a/actions/update.go b/actions/update.go index 607baa5..4935785 100644 --- a/actions/update.go +++ b/actions/update.go @@ -2,11 +2,12 @@ package actions import ( "fmt" + "jhman/clients/jd" + "jhman/model" + u "jhman/util" "log/slog" + "os" "time" - "zzman/clients/jd" - "zzman/model" - u "zzman/util" "gorm.io/gorm" ) @@ -140,7 +141,7 @@ func update(tx *gorm.DB, arg UpdateArgs) error { Id: config.Id, EdgeMac: u.P(edge.Macaddr), IsChange: u.P(0), - IsOnline: u.P(1), + IsOnline: u.P(0), }, } changesCreate = append(changesCreate, model.Change{ @@ -166,9 +167,11 @@ func update(tx *gorm.DB, arg UpdateArgs) error { step = time.Now() // 记录节点变更 - err = RecordChanges(tx, changesCreate) - if err != nil { - return fmt.Errorf("记录节点变更失败:%w", err) + if os.Getenv("DEBUG") == "true" { + err = RecordChanges(tx, changesCreate) + if err != nil { + return fmt.Errorf("记录节点变更失败:%w", err) + } } println(fmt.Sprintf("记录节点变更:%v", time.Since(step))) @@ -203,9 +206,11 @@ func update(tx *gorm.DB, arg UpdateArgs) error { } // 记录提交配置 - err = RecordSubmit(now, gateway, edges) - if err != nil { - return fmt.Errorf("记录网关 %s 提交配置失败:%w", gateway.Macaddr, err) + if os.Getenv("DEBUG") == "true" { + err = RecordSubmit(now, gateway, edges) + if err != nil { + return fmt.Errorf("记录网关 %s 提交配置失败:%w", gateway.Macaddr, err) + } } // 提交配置到云端:配置版本 gateway.ConfigVersion diff --git a/clients/jd/common.go b/clients/jd/common.go index f5e7278..608a710 100644 --- a/clients/jd/common.go +++ b/clients/jd/common.go @@ -6,11 +6,12 @@ import ( "encoding/json" "errors" "fmt" - "github.com/redis/go-redis/v9" "io" + "jhman/clients" "net/http" "time" - "zzman/clients" + + "github.com/redis/go-redis/v9" ) const base = "https://smart.jdbox.xyz:58001" diff --git a/go.mod b/go.mod index 9c8ec9b..89c0c8c 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module zzman +module jhman go 1.24.0 diff --git a/main.go b/main.go index c8b60d8..3247744 100644 --- a/main.go +++ b/main.go @@ -2,14 +2,14 @@ package main import ( "fmt" + "jhman/actions" + "jhman/clients" + "jhman/model" "log/slog" "os" "path/filepath" "slices" "strings" - "zzman/actions" - "zzman/clients" - "zzman/model" "github.com/joho/godotenv" slogjournal "github.com/systemd/slog-journal" diff --git a/rollback.sh b/rollback.sh new file mode 100644 index 0000000..db8842a --- /dev/null +++ b/rollback.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +# 此脚本应当运行在服务端,与 deploy.ps1 脚本上传到的位置配合,自动切换回退 + +cp cli cli.new +chmod -x cli.new + +chmod +x cli.bak +mv cli.bak cli + +echo 'done~' diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..d5fad79 --- /dev/null +++ b/update.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +# 此脚本应当运行在服务端,与 deploy.ps1 脚本上传到的位置配合,自动切换更新 + +cp cli cli.bak +chmod -x cli.bak + +chmod +x cli.new +mv cli.new cli + +echo 'done~'