_content/talks/2010/go_talk-20100323.html
package main
import "fmt"
func main() {
fmt.Printf("Hello, 世界\n")
}
package main
import (
"fmt"
"http"
)
func handler(c *http.Conn, r *http.Request) {
fmt.Fprintf(c, "Hello, %s.", r.URL.Path[1:])
}
func main() {
http.ListenAndServe(":8080",
http.HandlerFunc(handler))
}
#include <stdio.h> reads 360 lines from 9 files#include <iostream> reads 25,326 lines from 131 files#include <Carbon/Carbon.h> reads 124,730 lines from 689 filesimport "fmt" reads one file: 184 lines summarizing 7 packagesfind ~/go/src/pkg | grep _test.go$ | xargs wc -lgo keywordfunc main() {
go expensiveComputation(x, y, z)
anotherExpensiveComputation(a, b, c)
}
for {
rw := socket.Accept()
conn := newConn(rw, handler)
go conn.serve()
}
func main() {
go expensiveComputation(x, y, z)
anotherExpensiveComputation(a, b, c)
}
func computeAndSend(ch chan int, x, y, z int) {
ch <- expensiveComputation(x, y, z)
}
func main() {
ch := make(chan int)
go computeAndSend(ch, x, y, z)
v2 := anotherExpensiveComputation(a, b, c)
v1 := <-ch
fmt.Println(v1, v2)
}
<- operator) is sharing and synchronizationgoto is a control flow primitive; structured programming (if statements, for loops, function calls) is a control flow modeltype Point struct { X, Y int }
type Rect struct { P0, P1 Point }
// or ...
type Rect struct { X0, Y0, X1, Y1 int }