Go
Go is a statically and strongly typed, compiled programming language developed by a team at Google and many contributors from the open source community. The language is often referred to as “Golang” because of its domain name, golang.org, but the proper name is Go.
Useful links:
- Go official website
- Getting Started
- A Tour of Go
- How to Write Go Code
- Effective Go
- Packages
- Command Documentation
- Package testing
- Go by Example
Hello World
Programs start running in package main.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World!")
}
In Go, exported names must start with a capital letter, otherwise they will be private names (not accessible outside the package).
It is good style to use the “factored” import statement (when the code groups the imports into a parenthesized).
- Basic types
- Variables
- Constants
- iota
- Type conversions
- Overflow
- Strings
- Custom types
- for and “while”
- if
- switch
- Arrays
- Slices
- range
mapas
- nao sao ordenados
- em um range, a ordem e aleatoria
- lookup extremamente performatico
package main
import (
"fmt"
)
func main() {
amigos := map[string]int{
"alfredo": 5551234,
"joana": 9996674,
}
fmt.Println(amigos)
fmt.Println(amigos["joana"])
amigos["gopher"] = 444444
fmt.Println(amigos)
fmt.Println(amigos["gopher"], "\n\n")
// comma ok idiom
if será, ok := amigos["fantasma"]; !ok {
fmt.Println("não tem!")
} else {
fmt.Println(será)
}
}