diff options
author | Oleksandr Redko <Oleksandr_Redko@epam.com> | 2024-01-04 16:05:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 15:05:38 +0100 |
commit | 28615eba5594af29737938ae5cece50d7cba0a17 (patch) | |
tree | efb48c34b0d4372bdbbe4f89a06b7d3fb05baf75 /fs.go | |
parent | chore: move cookie fuzz test to go 1.18 fuzzing (#1686) (diff) | |
download | fasthttp-28615eba5594af29737938ae5cece50d7cba0a17.tar.gz fasthttp-28615eba5594af29737938ae5cece50d7cba0a17.tar.bz2 fasthttp-28615eba5594af29737938ae5cece50d7cba0a17.zip |
Change empty string checks to be more idiomatic (#1684)
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) |