mirror of
https://github.com/luthermonson/go-proxmox.git
synced 2026-04-26 01:15:57 +03:00
[GH-ISSUE #211] Custom UnmarshalJSON for VirtualMachineConfig to Avoid Duplicate Device Fields #60
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/go-proxmox#60
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @samuelemusiani on GitHub (Aug 26, 2025).
Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/211
Hi, I have a feature request: creating a custom UnmarshalJSON for the VirtualMachineConfig type.
Currently, the
VirtualMachineConfigstruct contains many duplicate fields for devices such asNet0,Net1, ..., and similar patterns for disks and other resources. This design is not ideal because it limits the number of resources on the VM. (Currently I can't have more than 10 network interfaces on the same VM).I want to implement the
func (vc *VirtualMachineConfig) UnmarshalJSON(data []byte) errormethod that will:Net0,Net1, ...) directly into their respective map fields (e.g.,Nets).Net0,Net1, ...) and instead keep all data inside the map, reducing duplication and making the struct easier to maintain and extend.I think that for a more clean code the numbered fields can be deleted, but this could be a breaking change.
Example
Instead of unmarshalling:
Into fields
Net0,Net1, ..., the custom unmarshaller should populate:And avoid the individual fields within the struct.
I can implement this.
I've also noticed that it exists a custom unmarshalig method for the ContainerConfig type that fills partially the maps inside the struct, but at the moment for the VirtualMachineConfig type this method does not exists so all the maps are always empty.
@samuelemusiani commented on GitHub (Aug 26, 2025):
For example if
vcis the virtualMachine config this could parse all the network interfaces:A similar thing must be done on all the other fields (SCSI, SATA, USBs, ecc.)