第10章_ネットワークプログラミング、33_ネットワークプログラミング_httpテストサーバー

httpサーバーを起動すると、ブラウザーはhttp://127.0.0.1:8000/goにアクセスし、ページにhellogoが出力されます。

ソースコード

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