Last active
April 26, 2019 11:21
-
-
Save jeffotoni/0eaf84a052d5e785afc240f2babfc389 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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