From 01030a52ba46889b85ee27cdc3d740d52fa76a13 Mon Sep 17 00:00:00 2001 From: Martin Riedl Date: Thu, 18 Mar 2021 19:02:34 +0100 Subject: [PATCH] enhanced prefix handling --- fs.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs.go b/fs.go index d7f7ed6..77dce66 100644 --- a/fs.go +++ b/fs.go @@ -65,16 +65,12 @@ func (fs *FS) ServeHTTP(w http.ResponseWriter, r *http.Request, info RoutingInfo func (fs *FS) findFile(url string) (fs.File, error) { // build file path filePath := path.Join(fs.FolderPrefix, url) - if strings.HasPrefix(filePath, "/") { - filePath = filePath[1:] - } + filePath = strings.TrimPrefix(filePath, "/") // check, if file exists in local folder if fs.UseLocalFolder { localFilePath := path.Join(fs.LocalFolderPrefix, filePath) - if strings.HasPrefix(localFilePath, "/") { - localFilePath = localFilePath[1:] - } + localFilePath = strings.TrimPrefix(localFilePath, "/") file, err := os.Open(localFilePath) if err == nil {