使用golang实现一个简单地httpServer
作者:互联网
golang标准库对于HttpServer有很好的支持。
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "request from %s\n", r.URL.Path)
}
func main() {
http.HandleFunc("/", handler)
log.Fatalln(http.ListenAndServe("localhost:8000", nil))
}
启动以后,使用curl
命令来测试
$ curl -i http://localhost:8000/test/foo/bar
后台输出:
request from /test/foo/bar
标签:httpServer,http,log,fmt,golang,handler,简单,curl 来源: https://blog.csdn.net/daguanjia11/article/details/121243504