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

let's go

let's go

Uma introdução sobre a linguagem go no devcamp 2013

Andrews Medina

May 11, 2013
Tweet

More Decks by Andrews Medina

Other Decks in Programming

Transcript

  1. globo .com @andrewsmedina ‣ dev na globo.com ‣ faz parte

    do time do tsuru paas ‣ contribui com projetos opensource (django, circus, splinter...) ‣ profeta nas horas vagas Saturday, May 11, 2013
  2. globo .com hello world package main import "fmt" func main()

    { fmt.Println("hello devcamp!") } Saturday, May 11, 2013
  3. globo .com hello world 2 - a missão package main

    import "fmt" func main() { nome := “andrews” fmt.Printf("meu nome é %s\n", nome) } Saturday, May 11, 2013
  4. globo .com for package main import "fmt" func main() {

    for i := 0; i <= 10; i++ { fmt.Println(i) } } Saturday, May 11, 2013
  5. globo .com primos func ehPrimo(numero int) bool { for i

    := 2; i < numero; i++ { if numero % i == 0 { return false } } return true } Saturday, May 11, 2013
  6. globo .com primos cont.. func main() { numeros := []int{3,

    5, 6, 7, 10, 11, 22, 32, 43, 111} for _, numero := range numeros { if ehPrimo(numero) { fmt.Printf("%d é primo.\n", numero) } } } Saturday, May 11, 2013
  7. globo .com methods type Carro struct { Modelo string }

    func (c *Carro) Acelera() { fmt.Printf("acelerando um %s...\n", c.Modelo) } Saturday, May 11, 2013
  8. globo .com interfaces type Moto struct { Modelo string }

    func (m *Moto) Acelera() { fmt.Printf("vrummmmm\n") } Saturday, May 11, 2013
  9. globo .com interfaces func aceleraQualquerCoisa(items []Aceleravel) { for _, aceleravel

    := range items { aceleravel.Acelera() } } Saturday, May 11, 2013
  10. globo .com interfaces c := Carro{Modelo: "Gol"} m := Moto{Modelo:

    "Harley"} aceleraQualquerCoisa([]Aceleravel{&c, &m}) Saturday, May 11, 2013
  11. globo .com bebedouro func main() { pessoas := []string{"andrews", "linus",

    "fowler"} for _, p := range pessoas { pegaAgua(p) go bebeAgua(p) } time.Sleep(1) } Saturday, May 11, 2013
  12. globo .com channels func soma(x, y int, c chan int)

    { c <- x + y } func main() { c := make(chan int) go soma(1, 1, c) go soma(2, 2, c) x, y := <-c, <-c fmt.Println(x+y) } Saturday, May 11, 2013
  13. globo .com baterias incluídas ‣ crypto ‣ encoding ‣ html/template

    ‣ image ‣ log/syslog ‣ net/http, net/mail, net/smtp Saturday, May 11, 2013
  14. globo .com baterias incluídas package main import ( "fmt" "net/http"

    ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "devcamp 2013") }) http.ListenAndServe("127.0.0.1:3333", nil) } Saturday, May 11, 2013
  15. globo .com baterias incluídas package main import ( "os" "text/template"

    ) func main() { t, _ := template.New("foo").Parse("Hello, {{.}}!") t.Execute(os.Stdout, "devcamp 2013") } Saturday, May 11, 2013
  16. globo .com quem já está usando go ‣ google ‣

    heroku ‣ mozilla ‣ globo.com ‣ canonical Saturday, May 11, 2013