Skip to content

Instantly share code, notes, and snippets.

@cn007b
Last active October 27, 2018 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cn007b/831925197950c501ec78093f23e15259 to your computer and use it in GitHub Desktop.
Save cn007b/831925197950c501ec78093f23e15259 to your computer and use it in GitHub Desktop.
GO ValueObject - vo part 3
// initName performs naive name validation (just for sake of example)
// and provides 100% guarantee that vo contains valid name.
func (i *Instance) initName(data map[string]string) {
name, exists := data["name"]
if !exists || name == "" {
i.errors["name"] = "invalid name"
return
}
i.name = name
}
// initEmail same like initName.
func (i *Instance) initEmail(data map[string]string) {
email, exists := data["email"]
if !exists || email == "" {
i.errors["email"] = "invalid email"
return
}
i.email = email
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment