package main import ( "fmt" "log" "net/http" ) // 主函数 func main() { //创建一个文件服务器,会去www目录下找index.html fileServer := http.FileServer(http.Dir("./www")) // 将 "/" 路径映射到文件服务器 http.Handle("/", fileServer) fmt.Printf("Starting server at port 9090\n") // 启动HTTP服务器并监听端口 80,如果出现错误,则打印错误信息并退出 if err := http.ListenAndServe(":9090", nil); err != nil { log.Fatal(err) } }