网络版
package main import ( "net/http" "fmt" ) func main() { http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { fmt.Fprintf(writer, "<h1>Hello World %s!</h1>", request.FormValue("name")) }) http.ListenAndServe(":8888", nil) }
并发版
package main import ( "fmt" "time" ) func printHelloWorld(i int, ch chan string) { ch <- fmt.Sprintf("Hellow World from goroutine %d!\n", i) } func main() { ch := make(chan string) for i:=0; i<5000; i++ { // go starts a go routine go printHelloWorld(i, ch) } for { msg := <- ch fmt.Println(msg) } time.Sleep(time.Millisecond) }