Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's Go

Jones Dias
February 09, 2019

Let's Go

Short introduction to Go

Jones Dias

February 09, 2019
Tweet

Other Decks in Programming

Transcript

  1. Readme Let’s Go! - Readme But WHY?! O time de

    devs do Google estava com problemas Preferência por Python e JS Compilação eficiente || execução eficiente || facilidade ao programar
  2. Readme Let’s Go! - Readme Um pouco de história Criada

    em 2008 no Google Robert Griesemer, Rob Pike e Ken Thompson Foi ao público em 2009
  3. Go Let’s Go! - Go Um pouco sobre a linguagem

    Linguagem de propósito geral Compilada Execução eficiente Open-source
  4. Go Let’s Go! - Go Um pouco sobre a linguagem

    OOP* C-like Concorrência Fortemente tipada Batteries included
  5. break default func interface select case defer go map struct

    chan else goto package switch const fallthrough if range type continue for import return var Let’s Go! - Go é simples
  6. Let’s Go! - Go 101 package main import ( "fmt"

    "math/rand" ) func main() { fmt.Println("Your number is %v\n", rand.Intn(10)) } Packages Go 101
  7. Let’s Go! - Go 101 package main import "fmt" func

    add(x int, y int) int { return x + y } func main() { fmt.Println(add(42, 13)) } Funções Go 101
  8. Let’s Go! - Go 101 package main import "fmt" func

    main() { var n int // zero value var i, j int = 1, 2 k := 3 c, python, java := true, false, "please, no!" fmt.Println(n,i, j, k, c, python, java) } // 0, 1, 2, 3, true, false, “no!” Variáveis Go 101
  9. Let’s Go! - Go 101 package main import "fmt" func

    main() { sum := 0 for i := 0; i < 10; i++ { sum += i } fmt.Println(sum) } Loops Go 101
  10. Let’s Go! - Go 101 package main import "fmt" func

    main() { x := 10 if x > 5 { fmt.Println(sqrt(x)) } else { fmt.Println(sqrt(x/2)) } } Condicionais Go 101
  11. Let’s Go! - Go 101 package main import "fmt" func

    main() { primes := [6]int{2, 3, 5, 7, 11, 13} fmt.Println(primes) } Arrays Go 101
  12. Let’s Go! - Go 101 package main import "fmt" func

    main() { primes := [6]int{2, 3, 5, 7, 11, 13} var s []int = primes[1:4] fmt.Println(s) } Slices Go 101
  13. Let’s Go! - Go 101 package main import "fmt" var

    libertadores map[string]int func main() { libertadores = make(map[string]int) libertadores["Santos"] = 3 fmt.Println(libertadores["Santos"]) } Map Go 101
  14. Let’s Go! - OOP package main import "fmt" type team

    struct { name string libertadores int } func main() { fmt.Println(team{name: "Santos", libertadores: 3}) } Structs OOP
  15. Let’s Go! - OOP ... func (t team) getLibertadores() int

    { return t.libertadores } func main() { t := team{name: "Santos", libertadores: 3} fmt.Printf("O peixão ganhou: %v libertadores\n", t.getLibertadores()) } Métodos OOP
  16. Let’s Go! - OOP ... type Anthem interface { Sing(lyrics

    string) } func (t team) Sing(lyrics string) { fmt.Println(lyrics) } func main() { t := team{name: "Santos", libertadores: 3} t.Sing("Agora quem dá bola é o Santos!") } Interfaces OOP
  17. Envio de valores de uma goroutine para outras Pipes que

    conectam uma goroutine a outras Let’s Go! - Channels
  18. Let’s Go! - Channels package main import "fmt" func main()

    { messages := make(chan string) go func() { messages <- "ping" }() msg := <-messages fmt.Println(msg) } Channels
  19. Let’s Go! - Dep $ mkdir -p $GOPATH/src/github.com/me/example $ cd

    $GOPATH/src/github.com/me/example $ curl https://raw.githubusercontent.com/golang/dep/master /install.sh | sh $ dep init $ ls Gopkg.toml Gopkg.lock vendor/
  20. Let’s Go! - Dep $ dep ensure -add github.com/foo/bar \

    github.com/baz/quux $ # more at \ https://golang.github.io/dep/docs/introduction.html
  21. Let’s Go! - Dep Um Go compiler feito para ser

    usado em lugares pequenos como microcontroladores, WebAssembly (WASM), e linha de comando https://github.com/tinygo-org/tinygo
  22. Let’s Go! - Materiais de estudo Materiais - Go By

    Example - A tour of Go - A linguagem Go - Aprenda Go
  23. Things in Go I Never Use - Mat Ryer Let’s

    Go! - Talks How Do You Structure Your Go Apps - Kat Zien Concurrency Is Not Parallelism - Rob Pike Go Concurrency Patterns - Google I/O 2012 - Rob Pike