【发布时间】:2020-09-22 04:06:44
【问题描述】:
我想通过将/fs 映射到磁盘中的filesys 来服务静态文件。我可以像这样服务器静态文件:
r := gin.New()
r.Use(static.Serve("/fs", static.LocalFile("./filesys", false)))
// followed by other routes definition such as R.GET()
我还想通过使用身份验证中间件来保护访问,而不影响其他路由。我想我需要像这样对 Gin 的小组做一些事情:
r := gin.New()
g := r.Group("/fs")
{ // what is the purpose of this parenthesis BTW?
g.Use(authMiddleWare)
g.Use(static.Serve("/fs", static.LocalFile(fileUploadDir, false)))
}
但是,我无法让它工作。它没有路由进来。如果我之后再做g.GET,路径就会出错。
如何解决这个问题?
【问题讨论】:
-
尝试通过
/fs/fs/xxx请求资源 -
@huggie 我删除了我的答案似乎是 3 年前已经在 git 上打开的问题 github.com/gin-contrib/static/issues/14