第十章_网络编程,33_网络编程_http测试服务器

启动一个http服务器,浏览器访问http://127.0.0.1:8000/go,页面打印hello go.

源代码

package main

import (
	"fmt"
	"net/http"
)

func myHandler(w http.ResponseWriter, r *http.Request) {
    
    
	fmt.Fprintln(w, "hello go")
}

func main() {
    
    
	http.HandleFunc("/go", myHandler)

	//在指定的地址进行监听,开启一个http
	http.ListenAndServe("127.0.0.1:8000", nil)
}

猜你喜欢

转载自blog.csdn.net/weixin_40355471/article/details/115288644