[GH-ISSUE #199] Zero values of configuration structs overwrite PVE API defaults #55

Open
opened 2026-03-03 15:29:55 +03:00 by kerem · 0 comments
Owner

Originally created by @xortim on GitHub (Jun 10, 2025).
Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/199

The zero values of all PVE configuration structs are overwriting the default values defined by the PVE API. This can lead to unexpected behavior for consumers who instantiate configuration structs without explicitly setting every field.

For example, in ContainerConfig, the Console field is defined as an IntOrBool, which defaults to 0 (false) in Go. However, according to the PVE API documentation, the expected default is 1 (true). This discrepancy means that if a consumer leaves Console unset, the resulting API call may disable the console even though it was not their intent.

type ContainerConfig struct {
...
	Console      IntOrBool        `json:"console,omitempty"`
...

This pattern occurs in multiple configuration structs throughout the codebase.

Expected behavior
If a field is not explicitly set by the consumer, the Proxmox API's default value should be preserved, not overwritten by Go's zero value.

Potential solution
Introduce pointer types for configuration fields where the PVE API has meaningful defaults. This allows omitempty to work correctly and avoids sending unintended zero values in API requests.

Additional context
This affects both usability and correctness, especially when consumers rely on the API to apply its documented defaults.

Originally created by @xortim on GitHub (Jun 10, 2025). Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/199 The zero values of all PVE configuration structs are overwriting the default values defined by the PVE API. This can lead to unexpected behavior for consumers who instantiate configuration structs without explicitly setting every field. For example, in `ContainerConfig`, the `Console` field is defined as an `IntOrBool`, which defaults to `0` (`false`) in Go. However, according to the [PVE API documentation](https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/lxc/{vmid}/config), the expected default is `1` (`true`). This discrepancy means that if a consumer leaves `Console` unset, the resulting API call may disable the console even though it was not their intent. ```go type ContainerConfig struct { ... Console IntOrBool `json:"console,omitempty"` ... ``` This pattern occurs in multiple configuration structs throughout the codebase. **Expected behavior** If a field is not explicitly set by the consumer, the Proxmox API's default value should be preserved, not overwritten by Go's zero value. **Potential solution** Introduce pointer types for configuration fields where the PVE API has meaningful defaults. This allows `omitempty` to work correctly and avoids sending unintended zero values in API requests. **Additional context** This affects both usability and correctness, especially when consumers rely on the API to apply its documented defaults.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/go-proxmox#55
No description provided.