#How does //+optional work?
1 messages ยท Page 1 of 1 (latest)
i'm staring at this for a bit till it sinks in https://github.com/dagger/dagger/pull/6179
it may be all i need
more specifically, this looks relevant as it seems to grep for // +
Docs where Optional transitions to // +optional
How does //+optional work?
Heya ๐
Yeah, so the way the pragmas work plays into how zenith works - we take your code as input, and then generate the contents of dagger.gen.go around it (which is what you see with dagger mod sync). The dagger.gen.go registers your functions with the dagger engine, marking any args that have the // +optional pragma as being optional ๐
This is actually exactly what was happening with Optional, but instead of inspecting the comments, we were inspecting the type of variables - the problem is that using the type is a bit unweidy, makes for some very complicated internal code in the generation of dagger.gen.go, and also the approach doesn't extend to defaults - which the pragma approach can neatly handle as well
FYI, there are some active conversations going on in https://discord.com/channels/707636530424053791/1204311531232428032
We don't want to have two different ways of specifying optionals in the first "official" release of modules, so one of them really needs to go - it looks like it'll be Optional, but it's up for debate as to how we get rid of it, and whether there's any cases where // +optional just isn't good enough (but Optional was)
thanks jed! i'm relatively new to go so seeing this Optional and then //+optional syntax is useful hints as to how people handle optional params in golang
hehe, we totally stole the idea for doing this from the k8s folks (and some weird internal go implementation code) ๐