mirror of
https://github.com/ayflying/p2p.git
synced 2026-03-05 01:39:23 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63f5bef038 | |||
| f90cf8b855 | |||
| a0f367efeb | |||
| ceb44e936f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,7 +16,6 @@ manifest/output/
|
|||||||
temp/
|
temp/
|
||||||
temp.yaml
|
temp.yaml
|
||||||
bin
|
bin
|
||||||
**/config/config.yaml
|
|
||||||
v1.0.0/
|
v1.0.0/
|
||||||
config/local.yaml
|
config/local.yaml
|
||||||
main.exe~
|
main.exe~
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/ayflying/p2p/internal/service"
|
"github.com/ayflying/p2p/internal/service"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"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/gctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,6 +20,14 @@ func init() {
|
|||||||
|
|
||||||
getDev, _ := g.Cfg().GetWithEnv(gctx.New(), "dev")
|
getDev, _ := g.Cfg().GetWithEnv(gctx.New(), "dev")
|
||||||
if !getDev.Bool() {
|
if !getDev.Bool() {
|
||||||
|
// 每天0点检查更新
|
||||||
|
gcron.Add(gctx.New(), "0 0 0 * * *", func(ctx context.Context) {
|
||||||
|
err := service.System().CheckUpdate()
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "检查更新失败:%v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
err := service.System().CheckUpdate()
|
err := service.System().CheckUpdate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Errorf(gctx.New(), "检查更新失败:%v", err)
|
g.Log().Errorf(gctx.New(), "检查更新失败:%v", err)
|
||||||
@@ -26,4 +37,4 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (system *sSystem) Init() {}
|
func (s *sSystem) Init() {}
|
||||||
|
|||||||
@@ -17,12 +17,15 @@ import (
|
|||||||
"github.com/ayflying/p2p/internal/service"
|
"github.com/ayflying/p2p/internal/service"
|
||||||
"github.com/gogf/gf/v2/encoding/gcompress"
|
"github.com/gogf/gf/v2/encoding/gcompress"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
"github.com/gogf/gf/v2/os/gcmd"
|
"github.com/gogf/gf/v2/os/gcmd"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 本地版本号(建议从编译参数注入,如 -ldflags "-X main.version=v0.1.3")
|
// 本地版本号(建议从编译参数注入,如 -ldflags "-X main.version=v0.1.3")
|
||||||
|
const versionFile = "version.txt"
|
||||||
|
|
||||||
var localVersion = "v0.0.0"
|
var localVersion = "v0.0.0"
|
||||||
|
|
||||||
// 对应 GitHub API 响应的核心字段(按需精简)
|
// 对应 GitHub API 响应的核心字段(按需精简)
|
||||||
@@ -58,6 +61,8 @@ func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) {
|
|||||||
if gzFile == "" {
|
if gzFile == "" {
|
||||||
gzFile = path.Join("download", platform+".gz")
|
gzFile = path.Join("download", platform+".gz")
|
||||||
}
|
}
|
||||||
|
//结束后删除压缩包
|
||||||
|
defer gfile.RemoveFile(gzFile)
|
||||||
|
|
||||||
ext := gfile.Ext(gzFile)
|
ext := gfile.Ext(gzFile)
|
||||||
if ext == ".zip" {
|
if ext == ".zip" {
|
||||||
@@ -84,6 +89,16 @@ func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) {
|
|||||||
|
|
||||||
// RestartSelf 实现 Windows 平台下的程序自重启
|
// RestartSelf 实现 Windows 平台下的程序自重启
|
||||||
func (s *sSystem) RestartSelf() error {
|
func (s *sSystem) RestartSelf() error {
|
||||||
|
ctx := gctx.New()
|
||||||
|
// 判断是否为linux平台
|
||||||
|
if runtime.GOOS == "linux" {
|
||||||
|
err := ghttp.RestartAllServer(ctx, os.Args[0])
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "重启失败:%v", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// 1. 获取当前程序的绝对路径
|
// 1. 获取当前程序的绝对路径
|
||||||
exePath, err := os.Executable()
|
exePath, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -187,7 +202,7 @@ func (s *sSystem) CheckUpdate() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
localVersion = gfile.GetContents("download/version.txt")
|
localVersion = gfile.GetContents(versionFile)
|
||||||
|
|
||||||
if s.isNewVersion(localVersion, latestVersion) {
|
if s.isNewVersion(localVersion, latestVersion) {
|
||||||
g.Log().Printf(ctx, "发现新版本:%s(当前版本:%s)", latestVersion, localVersion)
|
g.Log().Printf(ctx, "发现新版本:%s(当前版本:%s)", latestVersion, localVersion)
|
||||||
@@ -212,7 +227,7 @@ func (s *sSystem) CheckUpdate() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 保存最新版本号到文件
|
// 保存最新版本号到文件
|
||||||
gfile.PutContents("download/version.txt", latestVersion)
|
gfile.PutContents(versionFile, latestVersion)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
manifest/config/config.yaml
Normal file
46
manifest/config/config.yaml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
module:
|
||||||
|
server: true
|
||||||
|
client: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# https://goframe.org/docs/web/server-config-file-template
|
||||||
|
server:
|
||||||
|
address: "51888"
|
||||||
|
# openapiPath: "/api.json"
|
||||||
|
# swaggerPath: "/swagger"
|
||||||
|
dumpRouterMap: false
|
||||||
|
graceful: true
|
||||||
|
|
||||||
|
# https://goframe.org/docs/core/glog-config
|
||||||
|
logger:
|
||||||
|
level : "all"
|
||||||
|
stdout: true
|
||||||
|
|
||||||
|
# https://goframe.org/docs/core/gdb-config-file
|
||||||
|
database:
|
||||||
|
default:
|
||||||
|
link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||||
|
|
||||||
|
redis:
|
||||||
|
default:
|
||||||
|
address: "ay.cname.com:6379"
|
||||||
|
db: 15
|
||||||
|
pass: "12345678"
|
||||||
|
cache:
|
||||||
|
address: "ay.cname.com:6379"
|
||||||
|
db: 15
|
||||||
|
pass: "12345678"
|
||||||
|
|
||||||
|
p2p:
|
||||||
|
list:
|
||||||
|
# - host: "192.168.50.173"
|
||||||
|
# port: 51888
|
||||||
|
# ssl: false
|
||||||
|
# ws: ws
|
||||||
|
- host: "ay.cname.com"
|
||||||
|
port: 51888
|
||||||
|
ssl: false
|
||||||
|
ws: ws
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user