github更新库修复无法对比版本的问题

This commit is contained in:
2025-11-03 12:00:23 +08:00
parent 4c4db5e9e2
commit 610ae3aab2
7 changed files with 52 additions and 62 deletions

39
internal/boot/boot.go Normal file
View File

@@ -0,0 +1,39 @@
package boot
import (
"context"
updateGithub "github.com/ayflying/update-github-release"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcron"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gfile"
)
func Boot() {
getDev, _ := g.Cfg().GetWithEnv(gctx.New(), "dev")
if !getDev.Bool() {
var update = updateGithub.New("https://api.github.com/repos/ayflying/p2p/releases/latest")
gfile.PutContents("version.txt", "v0.0.9")
// 每天0点检查更新
gcron.Add(gctx.New(), "0 0 0 * * *", func(ctx context.Context) {
err := update.CheckUpdate(true)
if err != nil {
g.Log().Errorf(ctx, "检查更新失败:%v", err)
}
})
go func() {
//在协程中检查更新,预防主程序阻塞
err := update.CheckUpdate(true)
if err != nil {
g.Log().Errorf(gctx.New(), "检查更新失败:%v", err)
}
}()
} else {
g.Log().Debugf(gctx.New(), "开发模式,不检查更新")
}
}

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"time"
"github.com/ayflying/p2p/internal/boot"
"github.com/ayflying/p2p/internal/consts"
"github.com/ayflying/p2p/internal/controller/p2p"
"github.com/ayflying/p2p/internal/service"
@@ -31,6 +32,10 @@ var (
Brief: "start http server",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
g.Log().Debug(ctx, "开始执行main")
// 初始化服务器
boot.Boot()
Version, err := g.Cfg("hack").Get(ctx, "gfcli.build.version")
g.Log().Debugf(ctx, "当前启动的版本为:%v", Version)

View File

@@ -1,14 +1,5 @@
package system
import (
"context"
updateGithub "github.com/ayflying/update-github-release"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcron"
"github.com/gogf/gf/v2/os/gctx"
)
type sSystem struct{}
func New() *sSystem {
@@ -17,28 +8,6 @@ func New() *sSystem {
func init() {
getDev, _ := g.Cfg().GetWithEnv(gctx.New(), "dev")
if !getDev.Bool() {
var update = updateGithub.New("https://api.github.com/repos/ayflying/p2p/releases/latest")
// 每天0点检查更新
gcron.Add(gctx.New(), "0 0 0 * * *", func(ctx context.Context) {
err := update.CheckUpdate(true)
if err != nil {
g.Log().Errorf(ctx, "检查更新失败:%v", err)
}
})
go func() {
//在协程中检查更新,预防主程序阻塞
err := update.CheckUpdate(true)
if err != nil {
g.Log().Errorf(gctx.New(), "检查更新失败:%v", err)
}
}()
} else {
g.Log().Debugf(gctx.New(), "开发模式,不检查更新")
}
}
func (s *sSystem) Init() {}