<分区>
我是 Go 的初学者。 我尝试在我的本地计算机上构建一个静态 Web 服务器。 其实我已经读过了How do you serve a static html file using a go web server?
我的问题是,如果我有一个 Home.html
。
我想在链接 localhost:7777
时打开 Home.html
。
这就像 index.html
,但我想用 Home.html
替换 index.html
。
这是我的代码:
package main
import (
"fmt"
"net/http"
"log"
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello world!")
}
func main() {
http.HandleFunc("/", helloHandler)
//
err := http.ListenAndServe(":7777", nil)
if err != nil {
log.Fatal("ListenAndServe", err)
} else {
log.Println("listen 7777")
}
}
如何重写这段代码?
这个问题的关键字是什么?