http.FileSystem(http.Dir(...))
instead of gin.Dir(...,true)
GO-R1000If listDirectory
is true
for gin.Dir
, it could be directly replaced by
http.FileSystem(http.Dir(...))
to be more explicit of the behavior of the
function.
// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally
// in router.Static().
// if listDirectory == true, then it works the same as http.Dir() otherwise it returns
// a filesystem that prevents http.FileServer() to list the directory files.
func Dir(root string, listDirectory bool) http.FileSystem {
fs := http.Dir(root)
if listDirectory {
return fs
}
return &onlyFilesFS{fs}
}
Documentation of gin.Dir
also notes the same if true
is passed as an
argument to the listDirectory
parameter.
customFS := uFS{
FileSystem: gin.Dir(global.StaticPath, true),
}
r.Use(static.Serve("/", customFS))
customFS := uFS{
FileSystem: http.FileSystem(http.Dir(global.StaticPath)),
}
r.Use(static.Serve("/", customFS))