My implementation now looks like this. The
c := NewFooConfig()
c.Logger = localLogger
is overkill right now as we only have a single field in the config and could be simplified by
c := FooConfig{Logger: localLogger}
However, this is not future-proof if FooConfig gets more fields that get populated by NewFooConfig.
Other than that I think I’ve incorporated the main points of both @freeformz and @iignat:
NewBarshould not constructFooand rather take it as input.- Neither
NewFoonorNewBarshould force the user to supply optional parameters that have sensible defaults, but should have the option to do so.
Thanks!