diff options
Diffstat (limited to 'fs.go')
-rw-r--r-- | fs.go | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -100,7 +100,7 @@ func ServeFile(ctx *RequestCtx, path string) { rootFSHandler = rootFS.NewRequestHandler() }) - if len(path) == 0 || !filepath.IsAbs(path) { + if path == "" || !filepath.IsAbs(path) { // extend relative path to absolute path hasTrailingSlash := len(path) > 0 && (path[len(path)-1] == '/' || path[len(path)-1] == '\\') @@ -429,7 +429,7 @@ func (fs *FS) normalizeRoot(root string) string { // fs.FS uses relative paths, that paths are slash-separated on all systems, even Windows. if fs.FS == nil { // Serve files from the current working directory if Root is empty or if Root is a relative path. - if (!fs.AllowEmptyRoot && len(root) == 0) || (len(root) > 0 && !filepath.IsAbs(root)) { + if (!fs.AllowEmptyRoot && root == "") || (root != "" && !filepath.IsAbs(root)) { path, err := os.Getwd() if err != nil { path = "." @@ -452,14 +452,14 @@ func (fs *FS) initRequestHandler() { root := fs.normalizeRoot(fs.Root) compressRoot := fs.CompressRoot - if len(compressRoot) == 0 { + if compressRoot == "" { compressRoot = root } else { compressRoot = fs.normalizeRoot(compressRoot) } compressedFileSuffixes := fs.CompressedFileSuffixes - if len(compressedFileSuffixes["br"]) == 0 || len(compressedFileSuffixes["gzip"]) == 0 || + if compressedFileSuffixes["br"] == "" || compressedFileSuffixes["gzip"] == "" || compressedFileSuffixes["br"] == compressedFileSuffixes["gzip"] { // Copy global map compressedFileSuffixes = make(map[string]string, len(FSCompressedFileSuffixes)) @@ -1474,7 +1474,7 @@ func (h *fsHandler) newCompressedFSFileCache(f fs.File, fileInfo fs.FileInfo, fi ext := fileExtension(fileInfo.Name(), false, h.compressedFileSuffixes[fileEncoding]) contentType := mime.TypeByExtension(ext) - if len(contentType) == 0 { + if contentType == "" { data, err := readFileHeader(f, false, fileEncoding) if err != nil { return nil, fmt.Errorf("cannot read header of the file %q: %w", fileInfo.Name(), err) @@ -1573,7 +1573,7 @@ func (h *fsHandler) newFSFile(f fs.File, fileInfo fs.FileInfo, compressed bool, // detect content-type ext := fileExtension(fileInfo.Name(), compressed, h.compressedFileSuffixes[fileEncoding]) contentType := mime.TypeByExtension(ext) - if len(contentType) == 0 { + if contentType == "" { data, err := readFileHeader(f, compressed, fileEncoding) if err != nil { return nil, fmt.Errorf("cannot read header of the file %q: %w", fileInfo.Name(), err) |