使用通配符时无法正确提供静态文件

static files not served correctly when using wildcard

使用GOA, I defined a service to serve static files using a wildcard (as described in the documentation):

var _ = Service("static", func() { 
    Files("/static/*filepath", "./static/")
})

但是当我运行服务时,端点总是检索它在./static/[=36=中找到的所有内容] 目录,它似乎根本没有考虑通配符部分。

例如,如果我有 ./static/uploads/file1.jpg 并且我请求 localhost/static/uploads/file1.jpglocalhost/static/anything ,然后服务检索以下内容:

<pre>
<a href="uploads/">uploads/</a>
</pre>

深入研究代码,我认为问题出在生成的 /gen/http/static/server/server.go 文件中:

// Mount configures the mux to serve the static endpoints.
func Mount(mux goahttp.Muxer, h *Server) {
    MountCORSHandler(mux, h.CORS)
    MountStatic(mux, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        http.ServeFile(w, r, "./static/")
    }))
}

// MountStatic configures the mux to serve GET request made to
// "/static/*filepath".
func MountStatic(mux goahttp.Muxer, h http.Handler) {
    mux.Handle("GET", "/static/*filepath", handleStaticOrigin(h).ServeHTTP)
}

就我所见,无论如何,生成的代码都在为我们作为基本路径传递的内容提供服务,它根本不考虑我们是否配置了通配符(它仅使用它来匹配请求,但是不要自定义我们将提供的文件)。

我相信这在 v2 中工作正常,我在迁移到 v3 的过程中发现了这个问题。

正如我所说,这似乎是 GOA 中的一个错误,但也许我在这里遗漏了一些东西。我在回购中创建了一个问题以获取更多信息 (#2321)

根据 Github 问题 (#2321) 中的答案,文档中似乎有错误,我们应该在模式中使用大括号:

Thank you for the report, there is a typo in the docs, the path in the design needs to be /static/{*filepath} instead (with curly braces surrounding the wildcard).