Skip to content

Instantly share code, notes, and snippets.

@ankur22
Created May 30, 2020 13:53
Show Gist options
  • Save ankur22/01c5b0d1e2940b50c28059580d41d03d to your computer and use it in GitHub Desktop.
Save ankur22/01c5b0d1e2940b50c28059580d41d03d to your computer and use it in GitHub Desktop.
Example of struct embedding where there's two functions with same name, so we override that function
type logger struct{}
func (l *logger) do(in string) {
if l.validate(in) {
log.Println(in)
}
}
func (l *logger) validate(in string) bool {
if len(in) == 0 {
return false
}
return true
}
type checker struct{}
func (c *checker) validate(in string) bool {
if len(in) == 0 {
return false
}
return true
}
type loggerAndChecker struct {
*logger
*checker
}
func (l *loggerAndChecker) validate(in string) bool {
return l.logger.validate(in)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment