WIP: add jsonconv#345
Conversation
This package converts snake case (public_key) to camel case (PublicKey) for json output. We need this so all json generated by Uncloud has similar type of keys. Specificaly generate json from grpc using different keys (snake case) and this isn't easily changed, hence to two pass to fix things. This isn't a huge performance issue as this output is generated by running `uc`, it is not used for internal rpc or some such. Signed-off-by: Miek Gieben <miek@miek.nl>
|
Yeah thought about it, it also works, but more work to keep them in sync
(also we might be able to autogen most of it?)
In the long run this probably the best solution.
For now, this might work as an intermediate, but happy to attempt doing the
better thing now.
Also I think we should very clear about the unstable nature of the json
output for the time being.
…On Thu, Apr 30, 2026, 12:09 Pasha Sviderski ***@***.***> wrote:
*psviderski* left a comment (psviderski/uncloud#345)
<#345 (comment)>
What do you think about not directly exposing/using the internal gRPC
structs for the command output? Instead, create a new clean "view" struct
for the Machine where we can define the fields we want to show, the case,
and the values format, e.g. for enums. We should probably use that new
struct in the client as well as the public API so a user doesn't need to
work with more low-level auto-generated structs from the proto.
It's a bit more work to convert between them but fully owning the api
structs provides friendlier Go-native experience and allows to easily add
custom methods to them if needed.
IDK, am I not using proto the right way?
—
Reply to this email directly, view it on GitHub
<#345 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACWIWZMBDAQ7KFHAUFRHBT4YMQ6ZAVCNFSM6AAAAACYL6WCUWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DGNJRGU2TOMRUGE>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
I think I have an even better idea, even though this is hacky, but I think it will work. We do own the protobuf definition and it is just Go code, so why don't we rewrite the generated protobuf files and just update the - in our eyes - correct json tags..., I don't think they are used for something else that means reworking this PR in a go generate that becomes part of the build process. and look it already exists: https://github.com/fatih/gomodifytags |
til this is actually called pascalcase. type MachineInfo struct {
state protoimpl.MessageState `json:"State,omitempty"`
sizeCache protoimpl.SizeCache `json:"SizeCache,omitempty"`
unknownFields protoimpl.UnknownFields `json:"UnknownFields,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"Id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"Name,omitempty"`
Network *NetworkConfig `protobuf:"bytes,3,opt,name=network,proto3" json:"Network,omitempty"`
PublicIp *IP `protobuf:"bytes,4,opt,name=public_ip,json=publicIp,proto3" json:"PublicIp,omitempty"`
}is exactly what we want, and saves (a quite the hassle) redefining everything |
The serialised JSONs are stored in Corrosion in the It fixes JSON keys but does nothing for Go ergonomics. The caller still receives Proto types can't carry domain methods ( I think we still want to maintain Go-native domain data types at least for commonly used resources such as They also not always map 1:1 to the RPC wire data types. For example, we have Our Now, it would be great to draw a clear line what we should mirror/duplicate and what not. Mirroring all the proto types feels like it defeats the whole purpose of using proto in the first place. I don't know to be honest and I'm fine to not overthink it. I would probably not bother to recreate type like |
ah, then this route is a no-go
Very true. Hence the WIP status here, and good to have some docs on subject. Also saying somewhere that json outout just like the text output is not stable seems like a good starting point. |
What do you mean when you say JSON is not stable? What scenario do you have in your mind you want to warn about? |

This package converts snake case (public_key) to camel case (PublicKey) for json output. We need this so all json generated by Uncloud has similar type of keys.
Specificaly generate json from grpc using different keys (snake case) and this isn't easily changed, hence to two pass to fix things.
This isn't a huge performance issue as this output is generated by running
uc, it is not used for internal rpc or some such.See discussion in #342 if we want this or not.