mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-16 23:27:10 +08:00
added more context to the error message when opening a file
This commit is contained in:
parent
a481ee2897
commit
9ea47029d3
6
fs.go
6
fs.go
@ -5,6 +5,7 @@
|
|||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
@ -29,11 +30,12 @@ func Dir(root string, listDirectory bool) http.FileSystem {
|
|||||||
return &onlyFilesFS{fs}
|
return &onlyFilesFS{fs}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open conforms to http.Filesystem.
|
// Open opens a file excluding directories.
|
||||||
|
// It conforms to http.Filesystem.
|
||||||
func (fs onlyFilesFS) Open(name string) (http.File, error) {
|
func (fs onlyFilesFS) Open(name string) (http.File, error) {
|
||||||
f, err := fs.fs.Open(name)
|
f, err := fs.fs.Open(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to open file: %w", err)
|
||||||
}
|
}
|
||||||
return neuteredReaddirFile{f}, nil
|
return neuteredReaddirFile{f}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user