Go标准网络使用示例代码:GoNetworking

jopen 9年前

GoNetworking提供了一些示例代码演示了如何使用Go的标准网络库来进行明文和加密的通信。

package main  import (  . "fmt"  "net/http"  )  const MESSAGE = "hello world"  const ADDRESS = ":1024"  func main() {  http.HandleFunc("/hello", Hello)  if e := http.ListenAndServe(ADDRESS, nil); e != nil {  Println(e)  }  }  func Hello(w http.ResponseWriter, r *http.Request) {  w.Header().Set("Content-Type", "text/plain")  Fprintf(w, MESSAGE)  }

每一个示例都是自包含的程序,可以用下列命令启动:

go run .go



项目主页:http://www.open-open.com/lib/view/home/1416536860836