@thorstenball Go Ziele • "It must work at scale, for large programs with large numbers of dependencies, with large teams of programmers working on them.” • "It must be familiar, roughly C-like. [...] The need to get programmers productive quickly” • "It must be modern. [...] built in concurrency"
@thorstenball Go Variablen package main import "fmt" var i int = 1 var name string = "Go" func main() { var x int = 2 var y = 3 z := 4 s := "bob" fmt.Println(i, name, x, y, z, s) }
@thorstenball Go Flow-Control package main import "fmt" func main() { for i := 0; i < 10; i++ { if i % 2 == 0 { fmt.Println(i) } else { fmt.Println("no") } } // while == for sum := 1 for sum < 10 { sum += sum } }
@thorstenball Go Structs package main import "fmt" type Person struct { Age int Name string } func main() { var bob Person bob.Age = 24 bob.Name = "Bob" anna := Person{Age: 27, Name: "Anna"} fmt.Printf("Name: %s, Age: %d\n", bob.Name, bob.Age) fmt.Printf("Name: %s, Age: %d\n", anna.Name, anna.Age) }
@thorstenball Go Tools • Go hat viele Tools um mit Go-Code zu arbeiten • Der Großteil ist in der Standard-Installation enthalten • Tools sind sehr wichtig bei Go • Keine zusätzlichen Installationen nötig
@thorstenball Go Testing package foobar import "testing" func TestSayName(t *testing.T) { result := SayName() if result != "thorsten" { t.Error("result is wrong") } }
@thorstenball Go goroutines package main import "fmt" import "time" func ThreeTimes(line string) { for i := 0; i < 3; i++ { time.Sleep(100 * time.Millisecond) fmt.Println(line) } } func main() { go ThreeTimes("hello") ThreeTimes("world") } // Output: world hello world hello world