【发布时间】:2021-12-18 20:04:01
【问题描述】:
如果我运行 URL http://localhost:8080/ 我想运行 Index 函数,如果我运行 http://localhost:8080/robot.txt 它应该显示静态文件夹文件
func main() {
http.HandleFunc("/", Index)
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("static"))))
http.ListenAndServe(":8080", nil)
}
func Index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Index")
}
如何做到这一点。
目前,我收到此错误
恐慌:http:多次注册/
这是我的目录结构
main.go
static\
| robot.txt
| favicon.ico
| sitemap.xml
【问题讨论】: