mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-18 18:49:23 +08:00
feat: 自动更新
This commit is contained in:
26
main.go
26
main.go
@@ -10,10 +10,15 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/komari-monitor/komari-agent/config"
|
||||
"github.com/komari-monitor/komari-agent/monitoring"
|
||||
"github.com/komari-monitor/komari-agent/update"
|
||||
)
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
var (
|
||||
currentVersion = "v0.0.2"
|
||||
repo = "komari-monitor/komari-agent"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -43,6 +48,14 @@ func main() {
|
||||
ticker := time.NewTicker(time.Duration(localConfig.Interval * float64(time.Second)))
|
||||
defer ticker.Stop()
|
||||
|
||||
// Check for updates
|
||||
go func() {
|
||||
ticker_ := time.NewTicker(time.Duration(6) * time.Hour)
|
||||
for range ticker_.C {
|
||||
update_komari()
|
||||
}
|
||||
}()
|
||||
|
||||
for range ticker.C {
|
||||
// If no connection, attempt to connect
|
||||
if conn == nil {
|
||||
@@ -83,6 +96,17 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func update_komari() {
|
||||
// 初始化 Updater
|
||||
updater := update.NewUpdater(currentVersion, repo)
|
||||
|
||||
// 检查并更新
|
||||
err := updater.CheckAndUpdate()
|
||||
if err != nil {
|
||||
log.Fatalf("更新失败: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// connectWebSocket attempts to establish a WebSocket connection and upload basic info
|
||||
func connectWebSocket(websocketEndpoint, endpoint, token string) (*websocket.Conn, error) {
|
||||
dialer := &websocket.Dialer{
|
||||
|
Reference in New Issue
Block a user