我想在一个 golang 应用程序中创建两个 http 服务器。例子: package main import ( "io" "net/http")func helloOne(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello world one!")}func helloTwo(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello world two!")}func main() { // how to create two http server instatce? http.HandleFunc("/", helloOne) http.HandleFunc("/", helloTwo) go http.ListenAndServe(":8001", nil) http.ListenAndServe(":8002", nil)}如何创建两个 http 服务器实例并为它们添加处理程序?
1 回答
- 1 回答
- 0 关注
- 161 浏览
添加回答
举报
0/150
提交
取消