【发布时间】:2020-08-05 01:01:29
【问题描述】:
我创建了一个包含 index.html 文件的静态文件夹,在我的 go 文件中,我写道:
package main
import (
"net/http"
)
func main() {
http.Handle("/", http.FileServer(http.Dir("./static")))
http.ListenAndServe(":8482", nil)
}
在探索http://localhost:8482/时效果很好
我试着把代码写成:
http.Handle("/static", http.FileServer(http.Dir("./static")))
但在探索 http://localhost:8482/static 时失败,出现 404 错误
【问题讨论】:
-
试试:
http://localhost:8482/static/- 最后是/ -
@Vusal 同样的事情 :(
-
当前目录中的
static文件夹是您启动应用程序的位置吗?也可以试试绝对路径。 -
@HasanAYousef 我试过你的代码,它可以工作。可能是目录路径不正确
-
@icza 我添加了显示我的完整路径的屏幕截图
标签: go