我正在使用路由器(httprouter)并希望从根服务器提供静态文件。在Httprouter与静态文件的问题
static/style.css
CSS文件中的模板
<link href="./static/style.css" rel="stylesheet">
main.go
router := httprouter.New()
router.ServeFiles("/static/*filepath", http.Dir("/static/"))
router.GET("/", Index)
但http://localhost:3001/static/style.css给了我一个404错误,并且渲染页面中的样式也不起作用。
忽略“/ static /”中的尾部斜杠?除此之外,您可以尝试在路由器模块中添加一些Printfs以查看发生了什么。 –