多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 一个示例 ``` 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` 查看效果