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

Introdução a Go

Introdução a Go

Nesta palestra faço uma introdução a linguagem Go

Elton Minetto

May 11, 2022
Tweet

More Decks by Elton Minetto

Other Decks in Programming

Transcript

  1. Introdução a Go

    View Slide

  2. Elton Minetto
    ๏ Escrevo códigos, sou professor, palestrante, e
    escritor
    ๏ Escrevo no https://eltonminetto.dev e no
    twitter
    ๏ Sou Principal Software Engineer no PicPay

    View Slide

  3. O que é?

    View Slide

  4. Uma linguagem open
    source

    View Slide

  5. View Slide

  6. Por que uma
    nova
    linguagem?

    View Slide

  7. Muitos problemas com
    software em grande
    escala

    View Slide

  8. Velocidade de
    compilação

    View Slide

  9. Sistemas distribuídos
    Multicore

    View Slide

  10. Objetivos

    View Slide

  11. Semântica simples

    View Slide

  12. Tipagem estática

    View Slide

  13. Programação
    concorrente

    View Slide

  14. Divertida!

    View Slide

  15. TALK IS CHEAP,
    SHOW ME THE CODE!

    View Slide

  16. Pacotes
    package main
    import (
    "fmt"
    "math"
    )
    func main() {
    fmt.Printf("Now you have %g problems.", math.Sqrt(7))
    }

    View Slide

  17. Resultados Múltiplos
    package main
    import "fmt"
    func swap(x, y string) (string, string) {
    return y, x
    }
    func main() {
    a, b := swap("hello", "world")
    fmt.Println(a, b)
    }

    View Slide

  18. Erros
    package main
    import "github.com/coderockr/nfe/transmitter"
    func main() {
    response, err := transmitter.transmit(nfe, xml)
    if err != nil {
    panic("Error ") //tratamento de erro qualquer
    }
    result, err := transmitter.saveData(response, xml)
    if err != nil {
    panic("Error ") //tratamento de erro qualquer
    }
    }

    View Slide

  19. Goroutines
    package main
    import (
    "fmt"
    "time"
    )
    func say(s string) {
    for i := 0; i < 5; i++ {
    time.Sleep(100 * time.Millisecond)
    fmt.Println(s)
    }
    }
    func main() {
    go say("world")
    say("hello")
    }

    View Slide

  20. Canais
    package main
    import "fmt"
    func sum(s []int, c chan int) {
    sum := 0
    for _, v := range s {
    sum += v
    }
    c <- sum // send sum to c
    }
    func main() {
    s := []int{7, 2, 8, -9, 4, 0}
    c := make(chan int)
    go sum(s[:len(s)/2], c)
    go sum(s[len(s)/2:], c)
    x, y := <-c, <-c // receive from c
    fmt.Println(x, y, x+y)
    }

    View Slide

  21. Cross Compilation
    GOOS=darwin GOARCH=amd64 go build gorotines.go
    GOOS=windows GOARCH=amd64 go build gorotines.go
    GOOS=linux GOARCH=amd64 go build gorotines.go

    View Slide

  22. OO via composição e não herança, biblioteca
    padrão poderosa, etc.

    View Slide

  23. Quem está
    usando?

    View Slide

  24. Google, Basecamp, Globo.com, Canonical,
    DigitalOcean, Dropbox, Github, Heroku, Medium,
    Docker, MongoDB, Mozilla, Netflix, New Relic, New
    York Times, Resultados Digitais, Moip, Neoway,
    Walmart, Trybe, PicPay, etc
    https://github.com/golang/go/wiki/GoUsers

    View Slide

  25. Aplicações

    View Slide

  26. APIs

    View Slide

  27. Microservices

    View Slide

  28. IoT

    View Slide

  29. Databases

    View Slide

  30. CLIents

    View Slide

  31. Material de
    estudo

    View Slide

  32. Site oficial
    Tour
    Go, por onde começar?
    Livro: A Linguagem de Programação Go
    Curso Desenvolvimento Web com Go
    Awesome Go

    View Slide

  33. Contato
    [email protected]
    http://eltonminetto.dev
    http://twitter.com/eminetto

    View Slide