Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions 10-interfaces/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package main
import "fmt"

type Animal interface {
Shout() string
Gritar() string
}

type Cow struct{}
type Vaca struct{}

func (c *Cow) Shout() string {
func (c *Vaca) Gritar() string {
return "Muuu"
}

type Dog struct{}
type Cachorro struct{}

func (d *Dog) Shout() string {
func (d *Cachorro) Gritar() string {
return "Rau rau!"
}

func main() {
var animal Animal

animal = &Cow{}
callMyAnimal(animal)
animal = &Vaca{}
chamarMeuAnimal(animal)

animal = &Dog{}
callMyAnimal(animal)
animal = &Cachorro{}
chamarMeuAnimal(animal)
}

func callMyAnimal(a Animal) {
fmt.Println("My animal says:", a.Shout())
func chamarMeuAnimal(a Animal) {
fmt.Println("Meu animal diz:", a.Gritar())
}
22 changes: 11 additions & 11 deletions 5-structs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package main

import "fmt"

type Person struct {
Name string
Age int
Active bool
type Pessoa struct {
Nome string
Idade int
Ativo bool
}

func main() {
p := Person{
Name: "Wilson Júnior",
Age: 24,
Active: true,
p := Pessoa{
Nome: "Wilson Júnior",
Idade: 24,
Ativo: true,
}
fmt.Println("Nome", p.Name)
fmt.Println("Age", p.Age)
fmt.Println("Active", p.Active)
fmt.Println("Nome", p.Nome)
fmt.Println("Idade", p.Idade)
fmt.Println("Ativo", p.Ativo)
}
12 changes: 6 additions & 6 deletions 8-maps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package main
import "fmt"

func main() {
people := map[string]int{
pessoas := map[string]int{
"wilson": 25,
"andre": 26,
}

people["junior"] = 10
pessoas["junior"] = 10

for name, age := range people {
fmt.Printf("Chave %s do mapa valor: %d\n", name, age)
for nome, idade := range pessoas {
fmt.Printf("Chave %s do mapa valor: %d\n", nome, idade)
}

delete(people, "wilson")
fmt.Printf("Posição não alocada: %d\n", people["wilson"])
delete(pessoas, "wilson")
fmt.Printf("Posição não alocada: %d\n", pessoas["wilson"])
}
30 changes: 15 additions & 15 deletions 9-methods/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ package main

import "fmt"

type Person struct {
Name string
Age int
type Pessoa struct {
Nome string
Idade int
}

func (p *Person) String() string {
if p.Age < 18 {
return fmt.Sprintf("Olá jovem %s, seja bem vindo", p.Name)
} else if p.Age > 50 {
return fmt.Sprintf("Olá senhor %s, seja bem vindo", p.Name)
func (p *Pessoa) String() string {
if p.Idade < 18 {
return fmt.Sprintf("Olá jovem %s, seja bem vindo", p.Nome)
} else if p.Idade > 50 {
return fmt.Sprintf("Olá senhor %s, seja bem vindo", p.Nome)
}

return fmt.Sprintf("Olá %s, seja bem vindo", p.Name)
return fmt.Sprintf("Olá %s, seja bem vindo", p.Nome)
}

func (p *Person) privateMethod() int {
return p.Age * 4
func (p *Pessoa) privateMethod() int {
return p.Idade * 4
}

func main() {
person := Person{Name: "júnior", Age: 17}
fmt.Println(person.String())
pessoa := Pessoa{Nome: "júnior", Idade: 17}
fmt.Println(pessoa.String())

person = Person{Name: "Wilson", Age: 27}
pessoa = Pessoa{Nome: "Wilson", Idade: 27}
fmt.Println(person.String())

person = Person{Name: "Antônio", Age: 60}
pessoa = Pessoa{Nome: "Antônio", Idade: 60}
fmt.Println(person.String())

}