add mapstructure tags to types,

improve function documentation
This commit is contained in:
2026-05-26 20:22:50 +00:00
parent 48fa4c0613
commit 52ac2c2b97
3 changed files with 83 additions and 75 deletions
+33 -33
View File
@@ -1,10 +1,10 @@
package proxmoxaas_common_lib
type Pool struct {
PoolID string `json:"poolid"`
Groups []Group `json:"groups"`
Resources map[string]any `json:"resources"`
Templates Templates `json:"templates"`
PoolID string `json:"poolid" mapstructure:"poolid"`
Groups []Group `json:"groups" mapstructure:"groups"`
Resources map[string]any `json:"resources" mapstructure:"resources"`
Templates Templates `json:"templates" mapstructure:"templates"`
AllowedNodes map[string]bool `json:"nodes-allowed" mapstructure:"nodes-allowed"`
AllowedVMIDRange VMID `json:"vmid-allowed" mapstructure:"vmid-allowed"`
AllowedBackups Backups `json:"backups-allowed" mapstructure:"backups-allowed"`
@@ -14,32 +14,32 @@ type Pool struct {
// proxmox realms are formatted without realm values
// I assume that backends store groups by ID only and only proxmox will append the realm string
type Groupname struct {
GroupID string `json:"gid"`
Realm string `json:"realm"`
GroupID string `json:"gid" mapstructure:"gid"`
Realm string `json:"realm" mapstructure:"realm"`
}
type Group struct {
Groupname Groupname `json:"groupname"`
Role string `json:"role"` // role in owner pool
Users []User `json:"users"`
Groupname Groupname `json:"groupname" mapstructure:"groupname"`
Role string `json:"role" mapstructure:"role"` // role in owner pool
Users []User `json:"users" mapstructure:"users"`
}
type Username struct { // ie userid@realm
UserID string `json:"uid"`
Realm string `json:"realm"`
UserID string `json:"uid" mapstructure:"uid"`
Realm string `json:"realm" mapstructure:"realm"`
}
type User struct {
Username Username `json:"username"`
CN string `json:"cn"` // aka first name
SN string `json:"sn"` // aka last name
Mail string `json:"mail"`
Password string `json:"password"` // only used for POST requests
Username Username `json:"username" mapstructure:"username"`
CN string `json:"cn" mapstructure:"cn"` // aka first name
SN string `json:"sn" mapstructure:"sn"` // aka last name
Mail string `json:"mail" mapstructure:"mail"`
Password string `json:"password" mapstructure:"password"` // only used for POST requests
}
type VMID struct {
Min int `json:"min"`
Max int `json:"max"`
Min int `json:"min" mapstructure:"min"`
Max int `json:"max" mapstructure:"max"`
}
type Backups struct {
@@ -49,40 +49,40 @@ type Backups struct {
type Templates struct {
Instances struct {
LXC map[string]ResourceTemplate `json:"lxc"`
QEMU map[string]ResourceTemplate `json:"qemu"`
LXC map[string]ResourceTemplate `json:"lxc" mapstructure:"lxc"`
QEMU map[string]ResourceTemplate `json:"qemu" mapstructure:"qemu"`
} `json:"instances"`
}
type SimpleResource struct {
Limits struct {
Global SimpleLimit `json:"global"`
Nodes map[string]SimpleLimit `json:"nodes"`
Global SimpleLimit `json:"global" mapstructure:"global"`
Nodes map[string]SimpleLimit `json:"nodes" mapstructure:"nodes"`
} `json:"limits"`
}
type SimpleLimit struct {
Max int `json:"max"`
Max int `json:"max" mapstructure:"max"`
}
type MatchResource struct {
Limits struct {
Global []MatchLimit `json:"global"`
Nodes map[string][]MatchLimit `json:"nodes"`
Global []MatchLimit `json:"global" mapstructure:""`
Nodes map[string][]MatchLimit `json:"nodes" mapstructure:""`
} `json:"limits"`
}
type MatchLimit struct {
Match string `json:"match"`
Name string `json:"name"`
Max int `json:"max"`
Match string `json:"match" mapstructure:""`
Name string `json:"name" mapstructure:""`
Max int `json:"max" mapstructure:""`
}
type ResourceTemplate struct {
Value string `json:"value"`
Value string `json:"value" mapstructure:"value"`
Resource struct {
Enabled bool `json:"enabled"`
Name string `json:"name"`
Amount int `json:"amount"`
} `json:"resource"`
Enabled bool `json:"enabled" mapstructure:"enabled"`
Name string `json:"name" mapstructure:"name"`
Amount int `json:"amount" mapstructure:"amount"`
} `json:"resource" mapstructure:"resource"`
}