Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Trainings directly #35

Closed
wlopez-enkoding opened this issue Aug 5, 2021 · 1 comment
Closed

Creating Trainings directly #35

wlopez-enkoding opened this issue Aug 5, 2021 · 1 comment

Comments

@wlopez-enkoding
Copy link

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 !

@m110
Copy link
Member

m110 commented Aug 5, 2021

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:

func (r TrainingsFirestoreRepository) marshalTraining(tr *training.Training) TrainingModel {

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants