写了一个httpserver的简单小程序
import "net/http"
httpserver如下:
使用curl模拟客户端发送请求:
知识点:
1、使用go startserver,不然main函数在http.ListenAndServe监听堵塞,所以使用go另起一个协程实现监听
2、使用http.HandleFunc(partern,function(http.ResponseWriter,
*http.Request){})
HandleFunc接受两个参数,第一个为路由地址,第二个为处理方法。
3、curl 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。