mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-22 01:20:09 +01:00
Centralize Proxmox node configuration by moving `ProxmoxConfig` from `internal/types/idlewatcher.go` to a new `NodeConfig` struct in `internal/proxmox/node.go`. - Add `proxmox` field to route; allowing `proxy.app.proxmox` labels and corresponding route file config - Added `service` optional field to NodeConfig for service identification - Integrated Proxmox config directly into Route struct with proper validation - Propagate Proxmox settings to Idlewatcher during route validation - Updated swagger documentation to reflect schema changes
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package proxmox
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/bytedance/sonic"
|
|
"github.com/luthermonson/go-proxmox"
|
|
"github.com/yusing/goutils/pool"
|
|
)
|
|
|
|
type NodeConfig struct {
|
|
Node string `json:"node" validate:"required"`
|
|
VMID int `json:"vmid" validate:"required"`
|
|
Service string `json:"service,omitempty"`
|
|
} // @name ProxmoxNodeConfig
|
|
|
|
type Node struct {
|
|
name string
|
|
id string // likely node/<name>
|
|
client *proxmox.Client
|
|
}
|
|
|
|
var Nodes = pool.New[*Node]("proxmox_nodes")
|
|
|
|
func AvailableNodeNames() string {
|
|
if Nodes.Size() == 0 {
|
|
return ""
|
|
}
|
|
var sb strings.Builder
|
|
for _, node := range Nodes.Iter {
|
|
sb.WriteString(node.name)
|
|
sb.WriteString(", ")
|
|
}
|
|
return sb.String()[:sb.Len()-2]
|
|
}
|
|
|
|
func (n *Node) Key() string {
|
|
return n.name
|
|
}
|
|
|
|
func (n *Node) Name() string {
|
|
return n.name
|
|
}
|
|
|
|
func (n *Node) String() string {
|
|
return fmt.Sprintf("%s (%s)", n.name, n.id)
|
|
}
|
|
|
|
func (n *Node) MarshalJSON() ([]byte, error) {
|
|
return sonic.Marshal(map[string]any{
|
|
"name": n.name,
|
|
"id": n.id,
|
|
})
|
|
}
|
|
|
|
func (n *Node) Get(ctx context.Context, path string, v any) error {
|
|
return n.client.Get(ctx, path, v)
|
|
}
|