mirror of
https://github.com/ayflying/p2p.git
synced 2026-03-04 17:29:22 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b943b0cca | |||
| 03f762e910 | |||
| 84723248cd | |||
| d3f3687201 |
9
go.mod
9
go.mod
@@ -1,13 +1,15 @@
|
||||
module github.com/ayflying/p2p
|
||||
|
||||
go 1.24.0
|
||||
go 1.24.8
|
||||
|
||||
toolchain go1.24.9
|
||||
|
||||
require (
|
||||
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9
|
||||
github.com/dop251/goja v0.0.0-20250630131328-58d95d85e994
|
||||
github.com/getlantern/systray v1.2.2
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.3
|
||||
github.com/gogf/gf/v2 v2.9.3
|
||||
github.com/gogf/gf/v2 v2.9.4
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/libp2p/go-libp2p v0.43.0
|
||||
@@ -18,6 +20,7 @@ require (
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.5.0 // indirect
|
||||
github.com/ayflying/update-github-release v0.0.2 // indirect
|
||||
github.com/benbjohnson/clock v1.3.5 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
@@ -97,7 +100,7 @@ require (
|
||||
github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect
|
||||
github.com/olekukonko/errors v1.1.0 // indirect
|
||||
github.com/olekukonko/ll v0.1.1 // indirect
|
||||
github.com/olekukonko/tablewriter v1.0.9 // indirect
|
||||
github.com/olekukonko/tablewriter v1.1.0 // indirect
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
|
||||
github.com/philhofer/fwd v1.2.0 // indirect
|
||||
|
||||
6
go.sum
6
go.sum
@@ -15,6 +15,8 @@ github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod
|
||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/ayflying/update-github-release v0.0.2 h1:pZ2W0VKagBsJ5OsrREfniy/0fE70nbU8dJU7TtpzY0w=
|
||||
github.com/ayflying/update-github-release v0.0.2/go.mod h1:9ctXuagiEKABWLaS4ocRCUcnN77jdYm7zir7NQ+rIeM=
|
||||
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
|
||||
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
@@ -102,6 +104,8 @@ github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.3 h1:VTbeHq8XpBCWFIwBGmuBl+jP8Aep
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.3/go.mod h1:gcidgAYn4IWbx08QUThg7jw6bz3KklXI9/5zg8jnVHY=
|
||||
github.com/gogf/gf/v2 v2.9.3 h1:qjN4s55FfUzxZ1AE8vUHNDX3V0eIOUGXhF2DjRTVZQ4=
|
||||
github.com/gogf/gf/v2 v2.9.3/go.mod h1:w6rcfD13SmO7FKI80k9LSLiSMGqpMYp50Nfkrrc2sEE=
|
||||
github.com/gogf/gf/v2 v2.9.4 h1:6vleEWypot9WBPncP2GjbpgAUeG6Mzb1YESb9nPMkjY=
|
||||
github.com/gogf/gf/v2 v2.9.4/go.mod h1:Ukl+5HUH9S7puBmNLR4L1zUqeRwi0nrW4OigOknEztU=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
|
||||
@@ -283,6 +287,8 @@ github.com/olekukonko/ll v0.1.1 h1:9Dfeed5/Mgaxb9lHRAftLK9pVfYETvHn+If6lywVhJc=
|
||||
github.com/olekukonko/ll v0.1.1/go.mod h1:2dJo+hYZcJMLMbKwHEWvxCUbAOLc/CXWS9noET22Mdo=
|
||||
github.com/olekukonko/tablewriter v1.0.9 h1:XGwRsYLC2bY7bNd93Dk51bcPZksWZmLYuaTHR0FqfL8=
|
||||
github.com/olekukonko/tablewriter v1.0.9/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo=
|
||||
github.com/olekukonko/tablewriter v1.1.0 h1:N0LHrshF4T39KvI96fn6GT8HEjXRXYNDrDjKFDB7RIY=
|
||||
github.com/olekukonko/tablewriter v1.1.0/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo=
|
||||
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||
|
||||
@@ -2,29 +2,6 @@ package system
|
||||
|
||||
import "time"
|
||||
|
||||
type T struct {
|
||||
Url string `json:"url"`
|
||||
AssetsUrl string `json:"assets_url"`
|
||||
UploadUrl string `json:"upload_url"`
|
||||
HtmlUrl string `json:"html_url"`
|
||||
Id int `json:"id"`
|
||||
Author *Author `json:"author"`
|
||||
NodeId string `json:"node_id"`
|
||||
TagName string `json:"tag_name"`
|
||||
TargetCommitish string `json:"target_commitish"`
|
||||
Name string `json:"name"`
|
||||
Draft bool `json:"draft"`
|
||||
Immutable bool `json:"immutable"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
Assets []*Assets
|
||||
TarballUrl string `json:"tarball_url"`
|
||||
ZipballUrl string `json:"zipball_url"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type Author struct {
|
||||
Login string `json:"login"`
|
||||
Id int `json:"id"`
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/ayflying/p2p/internal/service"
|
||||
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"
|
||||
@@ -20,18 +21,23 @@ 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 := service.System().CheckUpdate()
|
||||
err := update.CheckUpdate()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "检查更新失败:%v", err)
|
||||
}
|
||||
})
|
||||
|
||||
err := service.System().CheckUpdate()
|
||||
if err != nil {
|
||||
g.Log().Errorf(gctx.New(), "检查更新失败:%v", err)
|
||||
}
|
||||
go func() {
|
||||
//在协程中检查更新,预防主程序阻塞
|
||||
err := update.CheckUpdate()
|
||||
if err != nil {
|
||||
g.Log().Errorf(gctx.New(), "检查更新失败:%v", err)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
g.Log().Debugf(gctx.New(), "开发模式,不检查更新")
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -69,12 +72,14 @@ func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) {
|
||||
g.Log().Debugf(ctx, "zip解压%v到%v", gzFile, gfile.Dir(runFile))
|
||||
err = gcompress.UnZipFile(gzFile, gfile.Dir(runFile))
|
||||
} else {
|
||||
g.Log().Debugf(ctx, "gzip解压%v到%v", gzFile, runFile)
|
||||
err = gcompress.UnGzipFile(gzFile, runFile)
|
||||
g.Log().Debugf(ctx, "gzip解压%v到%v", gzFile, gfile.Dir(runFile))
|
||||
err = s.UnTarGz(gzFile, gfile.Dir(runFile))
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
//修改文件权限为755
|
||||
err = gfile.Chmod(runFile, 0755)
|
||||
|
||||
go func() {
|
||||
log.Println("5秒后开始重启...")
|
||||
@@ -87,6 +92,64 @@ func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// UnTarGz 解压tar.gz文件到指定目录
|
||||
func (s *sSystem) UnTarGz(tarGzFileName, targetDir string) (err error) {
|
||||
// 打开tar.gz文件
|
||||
file, err := os.Open(tarGzFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// 创建gzip reader
|
||||
gzr, err := gzip.NewReader(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer gzr.Close()
|
||||
|
||||
// 创建tar reader
|
||||
tr := tar.NewReader(gzr)
|
||||
|
||||
// 遍历tar中的每个文件
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
// 到达文件末尾,退出循环
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 构建解压后的文件路径
|
||||
targetPath := targetDir + string(os.PathSeparator) + hdr.Name
|
||||
|
||||
// 如果是目录,创建目录
|
||||
if hdr.Typeflag == tar.TypeDir {
|
||||
err := os.MkdirAll(targetPath, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果是文件,创建文件并写入内容
|
||||
outFile, err := os.Create(targetPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer outFile.Close()
|
||||
|
||||
_, err = io.Copy(outFile, tr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// RestartSelf 实现 Windows 平台下的程序自重启
|
||||
func (s *sSystem) RestartSelf() error {
|
||||
ctx := gctx.New()
|
||||
|
||||
3
main.go
3
main.go
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
|
||||
//步骤1:加载驱动
|
||||
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
||||
|
||||
@@ -24,7 +23,7 @@ var (
|
||||
|
||||
func main() {
|
||||
g.Log().Infof(ctx, "启动文件最后修改时间:%v", gtime.New(gfile.MTime(gcmd.GetArg(0).String())).String())
|
||||
g.Dump("v1.0.0.2")
|
||||
//g.Dump("v1.0.0.2")
|
||||
|
||||
if ok := gfile.Exists("runtime"); !ok {
|
||||
gfile.Mkdir("runtime")
|
||||
|
||||
@@ -34,10 +34,10 @@ redis:
|
||||
|
||||
p2p:
|
||||
list:
|
||||
# - host: "192.168.50.173"
|
||||
# port: 51888
|
||||
# ssl: false
|
||||
# ws: ws
|
||||
- host: "host.yunloli.cn"
|
||||
port: 51888
|
||||
ssl: false
|
||||
ws: ws
|
||||
- host: "ay.cname.com"
|
||||
port: 51888
|
||||
ssl: false
|
||||
|
||||
Reference in New Issue
Block a user