Skip to content

Instantly share code, notes, and snippets.

@cn007b
Last active October 26, 2018 22:50
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/426ae39b1656f28215d77c77e2c22d8a to your computer and use it in GitHub Desktop.
Save cn007b/426ae39b1656f28215d77c77e2c22d8a to your computer and use it in GitHub Desktop.
GO ValueObject - vo part 2
// New creates new value object instance and performs validation.
func New(data map[string]string) (Instance, error) { // Instance intentionally value, not pointer
vo := Instance{}
vo.errors = make(map[string]string)
vo.initName(data)
vo.initEmail(data)
if len(vo.errors) > 0 {
// if you like panic, you may panic here
return vo, errors.New("invalid VO")
}
return vo, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment