krisnova / naml

Convert Kubernetes YAML to Golang
Apache License 2.0
1.26k stars 38 forks source link

A syntax question #27

Closed larsks closed 3 years ago

larsks commented 3 years ago

Sorry for what is probably a basic question, but why this...

Replicas: naml2.I32p(int32(v.exampleInt)),

Instead of this:

Replicas: v.exampleInt

? If I'm reading things correctly, that's returning a pointer to an integer, but elsewhere in the sample example you're able to use a literal integer without conversion, e.g.:

ContainerPort: 80

Thanks!

krisnova commented 3 years ago

The I32p() if just a convenience function to prevent us from having to cast an int() to an *int32().

There is no reason for that to be there other than for convenience sake. In the sample you suggested it looks to be superfluous. Feel free to open a PR if you want.

Also -- another consideration is that Go will type cast literals onto types if it can figure them out.


i := 0 // <--- i is now an int
var ii int32
ii = 0 // <--- i is now an int32

so if you are passing in a variable - you will need the convenience function - if you are defining it literally then go will type cast for you.

types are hard. hope this helps.