mirror of
https://github.com/luthermonson/go-proxmox.git
synced 2026-04-26 09:25:53 +03:00
[GH-ISSUE #69] json: cannot unmarshal string into Go struct field VirtualMachineConfig.cpulimit of type float32 #15
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#15
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 @ricardoalcantara on GitHub (Aug 8, 2023).
Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/69
I forgot to specify that it would came from string.
https://$PROXMOX_NODE_IP:8006/api2/json/nodes/$PROXMOX_NODE_NAME/qemu/$VMID/config
I actually didn't know about that, I learned if from here https://stackoverflow.com/a/9573928
I should have mapped something like this
This time I actually tested, sorry for the trouble!
@luthermonson commented on GitHub (Aug 9, 2023):
lol i like this little dig in the docs
This extra level of encoding is sometimes used when communicating with JavaScript programs:so i already accounted for this problem a couple times writing
StringOr<type>types which will sort of standardize this problem in the library. the string option is a valid solution but i liked to write some of the error checking around empty values and things cause the proxmox api can be a bit sketchy on typing sometimes... maybe you want to add aStringOrFLoat32and just use that?@ricardoalcantara commented on GitHub (Aug 9, 2023):
This time I tested the case where the field is empty too, so at least it's no breaking anymore. Since it's not working at the moment I would just set
,stringin the end so I could keep move on my project. I am new to GoLang to suggest more elaborate solution, I have been working with it for 3 months :) .If you are okay with this simple solution for now, I don't mind creating a new PR later.
[Edit]
I also noticed that all other float variables are float64, only the one I changed is float32, so even to calculation I have to make some casts, so my suggestion is also change CPULimit to float64 together in this change, what do you think about that?
@luthermonson commented on GitHub (Aug 9, 2023):
that's exactly what i was going to do, i started a StringOrFloat64 already... ill get a PR up and cut a new alpha release
@luthermonson commented on GitHub (Aug 9, 2023):
so just an FYI... i tested the
,stringidea and for the most part it was a mess and expected the value to always be a string and for some reason couldn't account for an empty string which was weird. the idea on the Or types was to be able to do both because I had found some APIs that were returning1234and another API returning a"1234"when ultimately the struct and I wanted to reuse my structs. this is just go minutia you probably don't care about but i promise you it's an interesting problem to solve!@ricardoalcantara commented on GitHub (Aug 9, 2023):
Thanks for your effort,I am eager to see that StringOrFloat64 implementation so I also could learn something new with it.
@luthermonson commented on GitHub (Aug 9, 2023):
it's not as exciting as you might think :D ill merge and cut a new alpha soon
@ricardoalcantara commented on GitHub (Aug 10, 2023):
Yes it is, I learned a lot with your pull request, I will remember it forever xD, thanks.