-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 05f7d21
Showing
14 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type ID int | ||
|
||
var ( | ||
a = true | ||
b ID = 1 | ||
c = "Gustavo" | ||
d float64 = 1.33 | ||
testArray [3]int | ||
) | ||
|
||
func main() { | ||
testArray[0] = 1 | ||
testArray[1] = 2 | ||
testArray[2] = 3 | ||
for i, v := range testArray { | ||
fmt.Printf("Index %d = %d\n", i, v) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module curso-go | ||
|
||
go 1.20 |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"curso-go/matematica" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
soma := matematica.Soma(10, 20) | ||
carro := matematica.Carro{name: "test"} | ||
fmt.Printf(carro) | ||
fmt.Println("Resultado: %v", soma) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package matematica | ||
|
||
func Soma[T int | float64](a, b T) T { | ||
return a + b | ||
} | ||
|
||
type Car struct { | ||
name string | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
func main() { | ||
for i := 0; i < 10; i++ { | ||
println(i) | ||
} | ||
|
||
numbers := []string{"Um", "Dois", "Tres"} | ||
for k, v := range numbers { | ||
println(k, v) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
s := []int{10, 20, 30, 40, 50} | ||
fmt.Printf("len=%d cap=%d %v\n", len(s[:2]), cap(s), s[:2]) | ||
fmt.Printf("len=%d cap=%d %v\n", len(s[:3]), cap(s[:3]), s[:3]) | ||
fmt.Printf("len=%d cap=%d %v\n", len(s[2:]), cap(s[2:]), s[2:]) | ||
|
||
s = append(s, 60) | ||
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s) | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
data := map[string]int{"Gustavo": 1000} | ||
fmt.Println(data["Gustavo"]) | ||
delete(data, "Gustavo") | ||
data["Gustav"] = 3000 | ||
fmt.Println(data["Gustav"]) | ||
|
||
for name, salar := range data { | ||
fmt.Printf("Nome: %s - Salario: %d\n", name, salar) | ||
} | ||
|
||
for _, salar := range data { | ||
fmt.Printf("Salario: %d\n", salar) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
resul, erro := sum(1, 2) | ||
if erro != nil { | ||
fmt.Println(erro) | ||
} | ||
fmt.Println(resul) | ||
} | ||
|
||
func sum(a int, b int) (int, error) { | ||
if a+b >= 50 { | ||
return 0, errors.New("Erro") | ||
} | ||
return a + b, nil | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
total := func() int { | ||
return sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 0) * 2 | ||
}() | ||
fmt.Println(total) | ||
} | ||
|
||
func sum(nums ...int) int { | ||
total := 0 | ||
for _, nume := range nums { | ||
total += nume | ||
} | ||
return total | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type Address struct { | ||
Street string | ||
City string | ||
State string | ||
Zip string | ||
} | ||
|
||
type Client struct { | ||
Name string | ||
Age int | ||
Active bool | ||
Addres Address | ||
} | ||
|
||
type People interface { | ||
Desactive() | ||
} | ||
|
||
func (c Client) Desactive() { | ||
c.Active = false | ||
fmt.Printf("Client: %s is desactivated", c.Name) | ||
} | ||
|
||
func Desativacao(pessoa People) { | ||
pessoa.Desactive() | ||
} | ||
|
||
func main() { | ||
gustavo := Client{ | ||
Name: "Gustavo", | ||
Age: 18, | ||
Active: true, | ||
} | ||
gustavo.Desactive() | ||
Desativacao(gustavo) | ||
fmt.Println(gustavo.Addres.City) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
type Client struct { | ||
name string | ||
} | ||
|
||
func teste(c Client) { | ||
println(c.name) | ||
} | ||
|
||
func main() { | ||
client := Client{ | ||
name: "Gustavo", | ||
} | ||
teste(client) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
var x interface{} = 10 | ||
showType(x) | ||
} | ||
|
||
func showType(t interface{}) { | ||
fmt.Printf("Type: %T - Value: %v\n", t, t) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
type MyNumber int | ||
|
||
type Number interface { | ||
~int | float64 | ||
} | ||
|
||
func somaSal[T Number](m map[string]T) T { | ||
var soma T | ||
for _, v := range m { | ||
soma = soma + v | ||
} | ||
return soma | ||
} | ||
|
||
func Compara[T comparable](a T, b T) bool { | ||
return a == b | ||
} | ||
|
||
func main() { | ||
m := map[string]int{"Gustavo": 3000, "Leonardo": 2000} | ||
n := map[string]MyNumber{"Gustavo": 3000, "Leonardo": 2000} | ||
println(somaSal(m)) | ||
println(somaSal(n)) | ||
println(Compara(1, 2)) | ||
} |