浏览代码

基础的http server使用

龚成明 2 年之前
父节点
当前提交
182acbb5f5
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      chapter01/07/server1.go

+ 16 - 0
chapter01/07/server1.go

@@ -0,0 +1,16 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+)
+
+func main() {
+	http.HandleFunc("/", handler)
+	log.Fatal(http.ListenAndServe("localhost:8000", nil))
+}
+
+func handler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "URL.Path = %q\n", r.URL.Path)
+}