From 229ab36ede6e9b77e765a95abfa0da86d750160e Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 15 Jan 2025 19:36:06 +0000 Subject: [PATCH] cleanup code --- app/app.go | 17 +++++++++++++++++ app/model.go | 1 - go.mod | 6 ++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index 562fcfd..be6fc81 100644 --- a/app/app.go +++ b/app/app.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "strconv" + "time" "github.com/gin-gonic/gin" "github.com/luthermonson/go-proxmox" @@ -18,6 +19,7 @@ var client ProxmoxClient func Run() { gob.Register(proxmox.Client{}) + gin.SetMode(gin.ReleaseMode) configPath := flag.String("config", "config.json", "path to config.json file") flag.Parse() @@ -34,6 +36,21 @@ func Run() { cluster.Init(client) cluster.Rebuild() + // set repeating update for full rebuilds + ticker := time.NewTicker(5 * time.Second) + channel := make(chan bool) + go func() { + for { + select { + case <-channel: + return + case <-ticker.C: + cluster.Rebuild() + log.Printf("rebuilt cluster\n") + } + } + }() + router.GET("/version", func(c *gin.Context) { PVEVersion, err := client.Version() if err != nil { diff --git a/app/model.go b/app/model.go index 67c27d9..02839d8 100644 --- a/app/model.go +++ b/app/model.go @@ -17,7 +17,6 @@ func (cluster *Cluster) Init(pve ProxmoxClient) { func (cluster *Cluster) Rebuild() error { cluster.Hosts = make(map[string]*Host) - //cluster.Instance = make(map[uint]*Instance) // get all nodes nodes, err := cluster.pve.Nodes() diff --git a/go.mod b/go.mod index eb36f5e..d113cf2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,10 @@ go 1.23 toolchain go1.23.2 -require github.com/luthermonson/go-proxmox v0.2.0 +require ( + github.com/gin-gonic/gin v1.10.0 + github.com/luthermonson/go-proxmox v0.2.0 +) require ( github.com/buger/goterm v1.0.4 // indirect @@ -16,7 +19,6 @@ require ( github.com/djherbis/times v1.6.0 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect - github.com/gin-gonic/gin v1.10.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect