🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一个示例 ``` 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` 查看效果