cleanup code
This commit is contained in:
parent
4269867661
commit
229ab36ede
17
app/app.go
17
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 {
|
||||
|
@ -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()
|
||||
|
6
go.mod
6
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user