Last active
October 26, 2018 22:50
-
-
Save cn007b/426ae39b1656f28215d77c77e2c22d8a to your computer and use it in GitHub Desktop.
GO ValueObject - vo part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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