## 一个示例 ``` package main import ( "log" "net/http" ) func main() { mux := &http.ServeMux{} // 路由 mux.HandleFunc("/hello1", hello) // 启动服务 log.Fatal(http.ListenAndServe(":8080", mux)) } func hello(writer http.ResponseWriter, request *http.Request) { writer.Write([]byte("hello!")) } ``` 敲入`go run app.go`运行 访问[http://localhost:8080/hello1](http://localhost:8080/hello1) 输出`hello!` ## 静态文件服务器 ``` package main import ( "fmt" "net/http" ) func main() { http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("/home/edk24/Desktop/")))) err := http.ListenAndServe(":8080", nil) if err != nil { fmt.Println(err) } } ``` 访问`http://localhost:8080/static` 查看效果