Skip to content

Commit 49fbf7c

Browse files
committed
Coerse string from PVE API to int
1 parent 328eed9 commit 49fbf7c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

api/qemu_type.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,28 @@ package api
22

33
import (
44
"encoding/json"
5+
"strconv"
6+
"strings"
57
)
68

9+
type StringOrInt int
10+
11+
func (d *StringOrInt) UnmarshalJSON(b []byte) error {
12+
str := strings.Replace(string(b), "\"", "", -1)
13+
if str == "" {
14+
*d = StringOrInt(0)
15+
return nil
16+
}
17+
18+
parsed, err := strconv.ParseInt(str, 10, 64)
19+
if err != nil {
20+
return err
21+
}
22+
23+
*d = StringOrInt(parsed)
24+
return nil
25+
}
26+
727
type VirtualMachine struct {
828
Cpu float32 `json:",omitempty"`
929
Cpus int `json:"cpus,omitempty"`
@@ -496,7 +516,7 @@ type VirtualMachineConfig struct {
496516
// specifies the QEMU machine type
497517
Machine string `json:"machine,omitempty"`
498518
// amount of RAM for the VM in MiB : 16 ~
499-
Memory int `json:"memory,omitempty"`
519+
Memory StringOrInt `json:"memory,omitempty"`
500520
MigrateDowntime json.Number `json:"migrate_downtime,omitempty"`
501521
MigrateSpeed int `json:"migrate_speed,omitempty"`
502522
// name for VM. Only used on the configuration web interface

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/k8s-proxmox/proxmox-go
1+
module github.com/gecgooden/proxmox-go
22

33
go 1.20
44

0 commit comments

Comments
 (0)