Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Last active April 26, 2019 11:21
Show Gist options
  • Select an option

  • Save jeffotoni/0eaf84a052d5e785afc240f2babfc389 to your computer and use it in GitHub Desktop.

Select an option

Save jeffotoni/0eaf84a052d5e785afc240f2babfc389 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type familia interface {
dados() string
}
type pai struct {
Nome string
Idade int
Cpf string `json:"campo-x"`
}
func (p pai) dados() string {
return fmt.Sprintf("Nome: %s, Idade: %d", p.Nome, p.Idade)
}
type filho struct {
pai
email string
}
func (f filho) dados() string {
return fmt.Sprintf("Nome: %s, Idade: %d, Email: %s", f.Nome, f.Idade, f.email)
}
func mostraDados(membro familia) {
fmt.Println(membro.dados())
}
func main() {
pai := new(pai)
pai.Nome = "Jeff"
pai.Idade = 50
pai.Cpf = "00.xxx.xxx-xx"
filho := new(filho)
filho.Nome = "Arthur"
filho.Idade = 20
filho.email = "arthur@gmail.com"
mostraDados(pai)
mostraDados(filho)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment