Go语言也被成为“自带电池”的语言,有大量的web相关工具集成在其中,构建web应用成了一件信手拈来的事情,只要调用http包的两个函数就可以了。
package mainimport ("fmt""net/http""log")func responseHello(w http.ResponseWriter, r *http.Request){//将字符串发送给客户端fmt.Fprintf(w, "Hello Golang!")}func main(){//设置要解析的URL路由http.HandleFunc("/", responseHello)//设置监听的端口,开始监听errInfo := http.ListenAndServe(":8080", nil) if errInfo != nil {log.Fatal("ListenAndServe: ", errInfo)}}