网络版

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)
}

 

相关文章:

  • 2021-10-11
  • 2021-11-26
  • 2022-02-09
  • 2021-06-03
  • 2021-07-02
  • 2022-12-23
猜你喜欢
  • 2022-01-21
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2021-11-28
  • 2021-10-21
  • 2021-10-30
相关资源
相似解决方案