-
-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for omitempty, as well as tests for omitempty. #81
Conversation
I've gone ahead and cleaned this up, turned into something a little more extendable. I've also taken out the concept that zero numeric values are "empty" and thus would appear in type Sample struct {
User string `toml:"name"`
Pass string `toml:"password,omitempty"`
Count int `toml:"count,omitzero"`
}
s := Sample{"username", "", 50}
// Encode =>
// name = "username"
// count = 50
//
s.Pass = "some password"
s.Count = 0
// Encode =>
// name = "username"
// password = "some password"
// |
Support for omitempty, as well as tests for omitempty.
Looks great! Thank you! |
It's unfortunate that omitzero is a separate concept from omitempty. This is an unnecessary break from encoding/json's behavior. |
See #120. |
When toml writes the config file it does not use `omitempty` for numeric values instead it requires `omitzero`. [1] The problem is that without this change, `config.Write()` writes ``` [machine] cpus = 0 disk_size = 0 memory = 0 ``` to the user file. Becuase podman machine system connection add code will do this the config file is broken afterwads. The first vm will be created successfully but after this every other vm will be broken because the cpu, memory and disk size are set to zero. [1] BurntSushi/toml#81 Fixes containers/podman#11824 Signed-off-by: Paul Holzinger <[email protected]>
When toml writes the config file it does not use `omitempty` for numeric values instead it requires `omitzero`. [1] The problem is that without this change, `config.Write()` writes ``` [machine] cpus = 0 disk_size = 0 memory = 0 ``` to the user file. Because podman machine system connection add code will do this the config file is broken afterwards. The first vm will be created successfully but after this every other vm will be broken because the cpu, memory and disk size are set to zero. [1] BurntSushi/toml#81 Fixes containers/podman#11824 Signed-off-by: Paul Holzinger <[email protected]>
When toml writes the config file it does not use `omitempty` for numeric values instead it requires `omitzero`. [1] The problem is that without this change, `config.Write()` writes ``` [machine] cpus = 0 disk_size = 0 memory = 0 ``` to the user file. Because podman machine system connection add code will do this the config file is broken afterwards. The first vm will be created successfully but after this every other vm will be broken because the cpu, memory and disk size are set to zero. [1] BurntSushi/toml#81 Fixes containers/podman#11824 Signed-off-by: Paul Holzinger <[email protected]>
When toml writes the config file it does not use `omitempty` for numeric values instead it requires `omitzero`. [1] The problem is that without this change, `config.Write()` writes ``` [machine] cpus = 0 disk_size = 0 memory = 0 ``` to the user file. Because podman machine system connection add code will do this the config file is broken afterwards. The first vm will be created successfully but after this every other vm will be broken because the cpu, memory and disk size are set to zero. [1] BurntSushi/toml#81 Fixes containers/podman#11824 Signed-off-by: Paul Holzinger <[email protected]>
This pull request will close #73 and add in support for omitempty.
If you want me to clean things up a bit, I can - this works fine but would not be the best structure to add in future "options" to field names.