Skip to content

Commit

Permalink
chore: deps up
Browse files Browse the repository at this point in the history
  • Loading branch information
yzy613 committed Oct 14, 2024
1 parent 5027d5c commit 5d61141
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"

- name: Test
run: go test ./...
Expand Down
52 changes: 15 additions & 37 deletions cmd/ddns-watchdog-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func main() {
}

// 加载服务配置
err = loadConf()
if err != nil {
if err = loadConf(); err != nil {
log.Fatal(err)
}

Expand Down Expand Up @@ -79,8 +78,7 @@ func processFlag() (exit bool, err error) {
for _, key := range arr {
fmt.Printf("%v\n\t%v\n", key, ncr[key])
}
exit = true
return
return true, nil
}

// 加载自定义配置文件目录
Expand All @@ -91,45 +89,31 @@ func processFlag() (exit bool, err error) {
// 有选择地初始化配置文件
if *initOption != "" {
for _, event := range *initOption {
err = initConf(string(event))
if err != nil {
if err = initConf(string(event)); err != nil {
return
}
}
exit = true
return
return true, nil
}

// 加载客户端配置
// 不得不放在这个地方,因为有下面的检查版本和安装 / 卸载服务
err = client.Client.LoadConf()
if err != nil {
if err = client.Client.LoadConf(); err != nil {
return
}

// 检查版本
if *version {
client.Client.CheckLatestVersion()
exit = true
return
return true, nil
}

// 安装 / 卸载服务
switch {
case *installOption:
err = client.Install()
if err != nil {
return
}
exit = true
return
return true, client.Install()
case *uninstallOption:
err = client.Uninstall()
if err != nil {
return
}
exit = true
return
return true, client.Uninstall()
}
return
}
Expand All @@ -151,7 +135,7 @@ func initConf(event string) (err error) {
err = errors.New("你初始化了一个寂寞")
}
if err != nil {
return err
return
}
log.Println(msg)
return
Expand All @@ -160,26 +144,22 @@ func initConf(event string) (err error) {
func loadConf() (err error) {
if !client.Client.Center.Enable {
if client.Client.Services.DNSPod {
err = client.DP.LoadConf()
if err != nil {
if err = client.DP.LoadConf(); err != nil {
return
}
}
if client.Client.Services.AliDNS {
err = client.AD.LoadConf()
if err != nil {
if err = client.AD.LoadConf(); err != nil {
return
}
}
if client.Client.Services.Cloudflare {
err = client.Cf.LoadConf()
if err != nil {
if err = client.Cf.LoadConf(); err != nil {
return
}
}
if client.Client.Services.HuaweiCloud {
err = client.HC.LoadConf()
if err != nil {
if err = client.HC.LoadConf(); err != nil {
return
}
}
Expand Down Expand Up @@ -278,8 +258,7 @@ func accessCenter(ipv4, ipv6 string) {
return
}
defer func(Body io.ReadCloser) {
t := Body.Close()
if t != nil {
if t := Body.Close(); t != nil {
err = t
}
}(resp.Body)
Expand All @@ -295,8 +274,7 @@ func accessCenter(ipv4, ipv6 string) {
}
if len(respBodyJson) > 0 {
var respBody = common.GeneralResp{}
err = json.Unmarshal(respBodyJson, &respBody)
if err != nil {
if err = json.Unmarshal(respBodyJson, &respBody); err != nil {
log.Println(err)
return
}
Expand Down
35 changes: 10 additions & 25 deletions cmd/ddns-watchdog-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func main() {

// 加载白名单
if server.Srv.CenterService {
err = server.Services.LoadConf()
if err != nil {
if err = server.Services.LoadConf(); err != nil {
log.Fatal(err)
}
// 路由绑定函数
Expand Down Expand Up @@ -94,13 +93,11 @@ func processFlag() (exit bool, err error) {
// 初始化配置
if *initOption != "" {
for _, event := range *initOption {
err = initConf(string(event))
if err != nil {
if err = initConf(string(event)); err != nil {
return
}
}
exit = true
return
return true, nil
}

if *deleteB {
Expand All @@ -114,8 +111,7 @@ func processFlag() (exit bool, err error) {
return
}
fmt.Print(msg)
exit = true
return
return true, nil
}

currentToken := ""
Expand Down Expand Up @@ -155,6 +151,7 @@ func processFlag() (exit bool, err error) {
}
}
exit = true

switch status {
case server.InsertSign:
fmt.Printf("Added %v(%v) to whitelist.\n", m, currentToken)
Expand All @@ -169,34 +166,22 @@ func processFlag() (exit bool, err error) {
}

// 加载配置
err = server.Srv.LoadConf()
if err != nil {
if err = server.Srv.LoadConf(); err != nil {
return
}

// 版本信息
if *version {
server.Srv.CheckLatestVersion()
exit = true
return
return true, nil
}

// 安装 / 卸载服务
switch {
case *installOption:
err = server.Install()
if err != nil {
return
}
exit = true
return
return true, server.Install()
case *uninstallOption:
err = server.Uninstall()
if err != nil {
return
}
exit = true
return
return true, server.Uninstall()
}
return
}
Expand All @@ -214,7 +199,7 @@ func initConf(event string) (err error) {
err = errors.New("你初始化了一个寂寞")
}
if err != nil {
return err
return
}
log.Println(msg)
return
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module ddns-watchdog

go 1.22
go 1.23

require (
github.com/aliyun/alibaba-cloud-sdk-go v1.62.758
github.com/aliyun/alibaba-cloud-sdk-go v1.63.27
github.com/bitly/go-simplejson v0.5.1
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.99
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.117
github.com/spf13/pflag v1.0.5
)

Expand All @@ -16,8 +16,8 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/tjfoc/gmsm v1.4.1 // indirect
go.mongodb.org/mongo-driver v1.15.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
go.mongodb.org/mongo-driver v1.17.1 // indirect
golang.org/x/crypto v0.28.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
26 changes: 14 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/aliyun/alibaba-cloud-sdk-go v1.62.758 h1:jAq1MJDZkNZlqSAmzdyu5vauCB2O1Ki8BsJNkcFER00=
github.com/aliyun/alibaba-cloud-sdk-go v1.62.758/go.mod h1:SOSDHfe1kX91v3W5QiBsWSLqeLxImobbMX1mxrFHsVQ=
github.com/aliyun/alibaba-cloud-sdk-go v1.63.27 h1:mDQ6eofwppTbmvlh8q3+76Oq3fAeN+TwpD/csiki5VE=
github.com/aliyun/alibaba-cloud-sdk-go v1.63.27/go.mod h1:SOSDHfe1kX91v3W5QiBsWSLqeLxImobbMX1mxrFHsVQ=
github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow=
github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -39,11 +39,12 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.99 h1:8uD68DJk2jmQ/zuU5yF41Mrmur9ltIIGAh+JFT68lIU=
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.99/go.mod h1:lhdEO9Bbb3hZ0wG+JeK9/GqMOp/sgc92mFmVk5tNSCk=
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.117 h1:TUiy5+4+Q7AWNfvKjQQL6lXOylnp7HL47JyYJ+HgN+I=
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.117/go.mod h1:JWz2ujO9X3oU5wb6kXp+DpR2UuDj2SldDbX8T0FSuhI=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand Down Expand Up @@ -94,8 +95,8 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0=
go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc=
go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -105,9 +106,9 @@ golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -156,13 +157,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -171,6 +172,7 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
16 changes: 6 additions & 10 deletions internal/client/alidns.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ func (ad *AliDNS) InitConf() (msg string, err error) {
}
ad.AccessKeySecret = ad.AccessKeyId

err = common.MarshalAndSave(ad, ConfDirectoryName+"/"+AliDNSConfFileName)
msg = "初始化 " + ConfDirectoryName + "/" + AliDNSConfFileName
return
return "初始化 " + ConfDirectoryName + "/" + AliDNSConfFileName,
common.MarshalAndSave(ad, ConfDirectoryName+"/"+AliDNSConfFileName)
}

func (ad *AliDNS) LoadConf() (err error) {
err = common.LoadAndUnmarshal(ConfDirectoryName+"/"+AliDNSConfFileName, &ad)
if err != nil {
if err = common.LoadAndUnmarshal(ConfDirectoryName+"/"+AliDNSConfFileName, &ad); err != nil {
return
}
if ad.AccessKeyId == "" || ad.AccessKeySecret == "" || ad.Domain == "" || (ad.SubDomain.A == "" && ad.SubDomain.AAAA == "") {
err = errors.New("请打开配置文件 " + ConfDirectoryName + "/" + AliDNSConfFileName + " 检查你的 access_key_id, access_key_secret, domain, sub_domain 并重新启动")
return errors.New("请打开配置文件 " + ConfDirectoryName + "/" + AliDNSConfFileName + " 检查你的 access_key_id, access_key_secret, domain, sub_domain 并重新启动")
}
return
}
Expand All @@ -50,8 +48,7 @@ func (ad *AliDNS) Run(enabled common.Enable, ipv4, ipv6 string) (msg []string, e
errs = append(errs, err)
} else if recordIP != ipv4 {
// 更新解析记录
err = ad.updateParseRecord(ipv4, recordId, "A", ad.SubDomain.A)
if err != nil {
if err = ad.updateParseRecord(ipv4, recordId, "A", ad.SubDomain.A); err != nil {
errs = append(errs, err)
} else {
msg = append(msg, "AliDNS: "+ad.SubDomain.A+"."+ad.Domain+" 已更新解析记录 "+ipv4)
Expand All @@ -65,8 +62,7 @@ func (ad *AliDNS) Run(enabled common.Enable, ipv4, ipv6 string) (msg []string, e
errs = append(errs, err)
} else if recordIP != ipv6 {
// 更新解析记录
err = ad.updateParseRecord(ipv6, recordId, "AAAA", ad.SubDomain.AAAA)
if err != nil {
if err = ad.updateParseRecord(ipv6, recordId, "AAAA", ad.SubDomain.AAAA); err != nil {
errs = append(errs, err)
} else {
msg = append(msg, "AliDNS: "+ad.SubDomain.AAAA+"."+ad.Domain+" 已更新解析记录 "+ipv6)
Expand Down
Loading

0 comments on commit 5d61141

Please sign in to comment.