#I am trying out constructors and I can't
1 messages · Page 1 of 1 (latest)
just a guess: you shouldn't need to both use Optional[foo] and // +optional. I don't think this will result in any weird double-optional behavior because it just boils down to an optional: true in the backend, but could be worth changing that to see if it fixes it. You could try // +default=17 :
func New(
// JDK version to download
// +default=17
jdkVersion Optional[string],
// Maven version to download
// +default=3.9.6
mavenVersion string,
) *Java {
return &Java{
jdkVersion: jdkVersion,
mavenVersion: mavenVersion,
}
}
oh but actually as I typed this out I realized the problem is that the fields are private, so they're not being carried around
try renaming those to JDKVersion string and MavenVersion string
oh boy.. yeah I bet that's it
yes that was it. The +optional and +default notation. Is that documented somewhere? I copied the +optional from someone else's code and didn't know it actually had a programmatic relevance. I thought that was just going to decorate the help
Still catching up to all the changes since the holidays haha
found this - https://github.com/dagger/dagger/issues/6162
I guess not documented yet.
Discord discussion: https://discord.com/channels/707636530424053791/1177373379255349248 As we need to add more support in Go for things like marking a field as private, setting default values, etc....
I was able to find some docs merged here: https://github.com/dagger/dagger/pull/6225 - but can't find where that's been deployed. I don't see it in the docs linked from Daggerverse at least. I know @jovial sand has a big overhaul of those docs in progress though, maybe it'll be included there.
https://docs.dagger.io/zenith/developer/go/525021/quickstart has the note and example about optional
Hey @jovial sand it will be useful to add an example of // +default flag also or at the minimum point to some documentation explaining how those comment flags work. Same goes for generic Optional
the generic Optional has been on a path to deprecation ever since we added the comments instead, since the code tends to look better
Oh! I didn't know that. The downside being no Go compiler support? Is that it?
Thanks, have opened an internal issue to track and add this
Yeah basically. I've found code looks a lot more natural/Go-like without Optional since zero-values are so ingrained into Go style, and Optional tends to lead you to needing 2x the amount of local vars (one tracking the Optional, another tracking the GetOr'd value)
I don't think you really lose much without it
The other advantage of //+default is that the default value makes its way into documentation, instead of being purely at runtime