#How does //+optional work?

1 messages ยท Page 1 of 1 (latest)

magic acorn
magic acorn
#
GitHub

This commit restructures and rewrites the Zenith quickstart. It provides a hands-on experience of creating a Daggerized pipeline using modules from the Daggerverse, whilst also walking the user thr...

Introduction

cerulean rapids
#

How does //+optional work?

acoustic hedge
#

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)

magic acorn
#

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

acoustic hedge
#

hehe, we totally stole the idea for doing this from the k8s folks (and some weird internal go implementation code) ๐Ÿ˜„