added more context to the error message when opening a file

This commit is contained in:
Saad 2023-10-15 15:53:53 +00:00
parent a481ee2897
commit 9ea47029d3

6
fs.go
View File

@ -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
} }