You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What's the best approach for us to provide struct initial values:
can we support hard coded values?
can we support calculated values? can we use values of other fields?
can we accept values as arguments?
require accepting values is problematic because it will break backward compatibility of no argument initialization in zero value of structs, reflect.New and other use cases. can we work around it somehow?
I had something like this in mind:
privatetypeFoostruct {
privatefieldAstring// zero valueprivatefieldBstring=1// hard coded valueprivate fieldC string=self.calculateFieldC() // calculated value
}
func (f*Foo) calculateFieldC() string {
returnf.fieldB*3
}
What's the best approach for us to provide struct initial values:
require accepting values is problematic because it will break backward compatibility of no argument initialization in zero value of structs,
reflect.New
and other use cases. can we work around it somehow?I had something like this in mind:
More context in this blog post section.
The text was updated successfully, but these errors were encountered: