go - Golang静态文件夹路径返回所有文件
问题描述
我有这个代码来打开静态文件夹
fs := http.FileServer(http.Dir("./static/"))
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))
但是当我要查找/static
路径时,它会返回此文件夹中的文件列表
例如
license.txt
logo.png
但我想返回一个空白页
解决方案
index.html
您可以在目录中添加空白./static/
,它将呈现为空白页面。
像这样的东西
<html>
<head><title>Nothing here</title></head>
<body><h1>Nothing here</h1></body>
</html>