3 ms·
I think there is a wider issue. Go simply does not provide a way to restrict the state of public struct fields. Enforcing the initialization of all fields achi
by fauigerzigerk 7y ago
I think there is a wider issue. Go simply does not provide a way to restrict the state of public struct fields.
Enforcing the initialization of all fields achieves relatively little given that public fields could easily be modified elsewhere. Requiring initialization to anything more specific than an automatic zero value is only useful in languages that have read-only fields.
So the only way to handle this in Go is to make struct fields private or accept that all combinations of public field values are valid (including the zero value) and deal with it at the point of use (or rather at all points of use).