Closed wlopez-enkoding closed 2 years ago
Hey @wlopez-enkoding!
The Training
has to be public so other packages are able to reference it. It's not used directly, but converted into other specific types, like here: https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/blob/c7273256574c598760498743d8ffa28b1b35acee/internal/trainings/adapters/trainings_firestore_repository.go#L117
You can create a Training
outside of the pacakge, but since all its fields are unexported, you won't be able to fill them. So in worst-case scenario, you'll create an empty training.
To make sure the passed value is valid, you can keep a check like if training == Training{}
or have a dedicated training.IsZero()
method.
Hey guys ! I was wondering why the Training struct is public... I mean, what happen if someone creates a Trining bypassing all required validations that exist in NewTraining ?
Thank you !
https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/blob/c7273256574c598760498743d8ffa28b1b35acee/internal/trainings/domain/training/training.go#L10