Skip to the content.

Back

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:

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).

mapas

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á)
	}

}