| 1 | // Copyright 2015 Matthew Holt and The Caddy Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package fileserverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/ |
| 16 | |
| 17 | import ( |
| 18 | "contextscip-go gomod github.com/golang/go/src go1.25.1 context/" |
| 19 | "io/fsscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/" |
| 20 | "net/urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/" |
| 21 | "osscip-go gomod github.com/golang/go/src go1.25.1 os/" |
| 22 | "pathscip-go gomod github.com/golang/go/src go1.25.1 path/" |
| 23 | "slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/" |
| 24 | "sortscip-go gomod github.com/golang/go/src go1.25.1 sort/" |
| 25 | "strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/" |
| 26 | "stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/" |
| 27 | "timescip-go gomod github.com/golang/go/src go1.25.1 time/" |
| 28 | |
| 29 | "github.com/dustin/go-humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/" |
| 30 | "go.uber.org/zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/" |
| 31 | "go.uber.org/zap/zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/" |
| 32 | |
| 33 | "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/" |
| 34 | "github.com/caddyserver/caddy/v2/modules/caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/" |
| 35 | ) |
| 36 | |
| 37 | func (fsrv *FileServerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/FileServer#) directoryListingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/FileServer#directoryListing().(ctx contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#, fileSystem fsscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/.FSscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FS#, parentModTime timescip-go gomod github.com/golang/go/src go1.25.1 time/.Timescip-go gomod github.com/golang/go/src go1.25.1 time/Time#, entries []fsscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/.DirEntryscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/DirEntry#, canGoUp bool, root, urlPath string, repl *caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#) *browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext# { |
| 38 | filesToHide := fsrv.transformHidePathsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/FileServer#transformHidePaths().(repl) |
| 39 | |
| 40 | name, _ := urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.PathUnescapescip-go gomod github.com/golang/go/src go1.25.1 `net/url`/PathUnescape().(urlPath) |
| 41 | |
| 42 | tplCtx := &browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#{ |
| 43 | Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Name.: pathscip-go gomod github.com/golang/go/src go1.25.1 path/.Basescip-go gomod github.com/golang/go/src go1.25.1 path/Base().(name), |
| 44 | Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Path.: urlPath, |
| 45 | CanGoUpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#CanGoUp.: canGoUp, |
| 46 | lastModifiedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#lastModified.: parentModTime, |
| 47 | } |
| 48 | |
| 49 | for _, entry := range entries { |
| 50 | if err := ctx.Errscip-go gomod github.com/golang/go/src go1.25.1 context/Context#Err().(); err != nil { |
| 51 | break |
| 52 | } |
| 53 | |
| 54 | name := entry.Namescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/DirEntry#Name().() |
| 55 | |
| 56 | if fileHiddenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileHidden().(name, filesToHide) { |
| 57 | continue |
| 58 | } |
| 59 | |
| 60 | info, err := entry.Infoscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/DirEntry#Info().() |
| 61 | if err != nil { |
| 62 | if c := fsrv.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/FileServer#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel., "could not get info about directory entry"); c != nil { |
| 63 | c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("name", entry.Namescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/DirEntry#Name().()), zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("root", root)) |
| 64 | } |
| 65 | continue |
| 66 | } |
| 67 | |
| 68 | // keep track of the most recently modified item in the listing |
| 69 | modTime := info.ModTimescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#ModTime().() |
| 70 | if tplCtx.lastModifiedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#lastModified..IsZeroscip-go gomod github.com/golang/go/src go1.25.1 time/Time#IsZero().() || modTime.Afterscip-go gomod github.com/golang/go/src go1.25.1 time/Time#After().(tplCtx.lastModifiedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#lastModified.) { |
| 71 | tplCtx.lastModifiedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#lastModified. = modTime |
| 72 | } |
| 73 | |
| 74 | isDir := entry.IsDirscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/DirEntry#IsDir().() || fsrv.isSymlinkTargetDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/FileServer#isSymlinkTargetDir().(fileSystem, info, root, urlPath) |
| 75 | |
| 76 | // add the slash after the escape of path to avoid escaping the slash as well |
| 77 | if isDir { |
| 78 | name += "/" |
| 79 | tplCtx.NumDirsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#NumDirs.++ |
| 80 | } else { |
| 81 | tplCtx.NumFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#NumFiles.++ |
| 82 | } |
| 83 | |
| 84 | size := info.Sizescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#Size().() |
| 85 | |
| 86 | if !isDir { |
| 87 | // increase the total by the symlink's size, not the target's size, |
| 88 | // by incrementing before we follow the symlink |
| 89 | tplCtx.TotalFileSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#TotalFileSize. += size |
| 90 | } |
| 91 | |
| 92 | fileIsSymlink := isSymlinkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/isSymlink().(info) |
| 93 | symlinkPath := "" |
| 94 | if fileIsSymlink { |
| 95 | path := caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SanitizedPathJoinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SanitizedPathJoin().(root, pathscip-go gomod github.com/golang/go/src go1.25.1 path/.Joinscip-go gomod github.com/golang/go/src go1.25.1 path/Join().(urlPath, info.Namescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#Name().())) |
| 96 | fileInfo, err := fsscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/.Statscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/Stat().(fileSystem, path) |
| 97 | if err == nil { |
| 98 | size = fileInfo.Sizescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#Size().() |
| 99 | } |
| 100 | |
| 101 | if fsrv.Browsescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/FileServer#Browse..RevealSymlinksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/Browse#RevealSymlinks. { |
| 102 | symLinkTarget, err := osscip-go gomod github.com/golang/go/src go1.25.1 os/.Readlinkscip-go gomod github.com/golang/go/src go1.25.1 os/Readlink().(path) |
| 103 | if err == nil { |
| 104 | symlinkPath = symLinkTarget |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // An error most likely means the symlink target doesn't exist, |
| 109 | // which isn't entirely unusual and shouldn't fail the listing. |
| 110 | // In this case, just use the size of the symlink itself, which |
| 111 | // was already set above. |
| 112 | } |
| 113 | |
| 114 | if !isDir { |
| 115 | // increase the total including the symlink target's size |
| 116 | tplCtx.TotalFileSizeFollowingSymlinksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#TotalFileSizeFollowingSymlinks. += size |
| 117 | } |
| 118 | |
| 119 | u := urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#{Pathscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#Path.: "./" + name} // prepend with "./" to fix paths with ':' in the name |
| 120 | |
| 121 | tplCtx.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items. = append(tplCtx.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items., fileInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#{ |
| 122 | IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir.: isDir, |
| 123 | IsSymlinkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsSymlink.: fileIsSymlink, |
| 124 | Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.: name, |
| 125 | Sizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Size.: size, |
| 126 | URLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#URL.: u.Stringscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#String().(), |
| 127 | ModTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#ModTime.: modTime.UTCscip-go gomod github.com/golang/go/src go1.25.1 time/Time#UTC().(), |
| 128 | Modescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Mode.: info.Modescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#Mode().(), |
| 129 | Tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Tpl.: tplCtx, // a reference up to the template context is useful |
| 130 | SymlinkPathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#SymlinkPath.: symlinkPath, |
| 131 | }) |
| 132 | } |
| 133 | |
| 134 | // this time is used for the Last-Modified header and comparing If-Modified-Since from client |
| 135 | // both are expected to be in UTC, so we convert to UTC here |
| 136 | // see: https://github.com/caddyserver/caddy/issues/6828 |
| 137 | tplCtx.lastModifiedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#lastModified. = tplCtx.lastModifiedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#lastModified..UTCscip-go gomod github.com/golang/go/src go1.25.1 time/Time#UTC().() |
| 138 | return tplCtx |
| 139 | } |
| 140 | |
| 141 | // browseTemplateContext provides the template context for directory listings. |
| 142 | type browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext# struct { |
| 143 | // The name of the directory (the last element of the path). |
| 144 | Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Name. string `json:"name"` |
| 145 | |
| 146 | // The full path of the request. |
| 147 | Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Path. string `json:"path"` |
| 148 | |
| 149 | // Whether the parent directory is browsable. |
| 150 | CanGoUpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#CanGoUp. bool `json:"can_go_up"` |
| 151 | |
| 152 | // The items (files and folders) in the path. |
| 153 | Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items. []fileInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo# `json:"items,omitempty"` |
| 154 | |
| 155 | // If ≠0 then Items starting from that many elements. |
| 156 | Offsetscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Offset. int `json:"offset,omitempty"` |
| 157 | |
| 158 | // If ≠0 then Items have been limited to that many elements. |
| 159 | Limitscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Limit. int `json:"limit,omitempty"` |
| 160 | |
| 161 | // The number of directories in the listing. |
| 162 | NumDirsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#NumDirs. int `json:"num_dirs"` |
| 163 | |
| 164 | // The number of files (items that aren't directories) in the listing. |
| 165 | NumFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#NumFiles. int `json:"num_files"` |
| 166 | |
| 167 | // The total size of all files in the listing. Only includes the |
| 168 | // size of the files themselves, not the size of symlink targets |
| 169 | // (i.e. the calculation of this value does not follow symlinks). |
| 170 | TotalFileSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#TotalFileSize. int64 `json:"total_file_size"` |
| 171 | |
| 172 | // The total size of all files in the listing, including the |
| 173 | // size of the files targeted by symlinks. |
| 174 | TotalFileSizeFollowingSymlinksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#TotalFileSizeFollowingSymlinks. int64 `json:"total_file_size_following_symlinks"` |
| 175 | |
| 176 | // Sort column used |
| 177 | Sortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Sort. string `json:"sort,omitempty"` |
| 178 | |
| 179 | // Sorting order |
| 180 | Orderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Order. string `json:"order,omitempty"` |
| 181 | |
| 182 | // Display format (list or grid) |
| 183 | Layoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Layout. string `json:"layout,omitempty"` |
| 184 | |
| 185 | // The most recent file modification date in the listing. |
| 186 | // Used for HTTP header purposes. |
| 187 | lastModifiedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#lastModified. timescip-go gomod github.com/golang/go/src go1.25.1 time/.Timescip-go gomod github.com/golang/go/src go1.25.1 time/Time# |
| 188 | } |
| 189 | |
| 190 | // Breadcrumbs returns l.Path where every element maps |
| 191 | // the link to the text to display. |
| 192 | func (l browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#) Breadcrumbsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Breadcrumbs().() []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb# { |
| 193 | if len(l.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Path.) == 0 { |
| 194 | return []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{} |
| 195 | } |
| 196 | |
| 197 | // skip trailing slash |
| 198 | lpath := l.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Path. |
| 199 | if lpath[len(lpath)-1] == '/' { |
| 200 | lpath = lpath[:len(lpath)-1] |
| 201 | } |
| 202 | parts := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.1 strings/Split().(lpath, "/") |
| 203 | result := make([]crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#, len(parts)) |
| 204 | for i, p := range parts { |
| 205 | if i == 0 && p == "" { |
| 206 | p = "/" |
| 207 | } |
| 208 | // the directory name could include an encoded slash in its path, |
| 209 | // so the item name should be unescaped in the loop rather than unescaping the |
| 210 | // entire path outside the loop. |
| 211 | p, _ = urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.PathUnescapescip-go gomod github.com/golang/go/src go1.25.1 `net/url`/PathUnescape().(p) |
| 212 | lnk := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.1 strings/Repeat().("../", len(parts)-i-1) |
| 213 | result[i] = crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: lnk, Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: p} |
| 214 | } |
| 215 | |
| 216 | return result |
| 217 | } |
| 218 | |
| 219 | func (l *browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#) applySortAndLimitscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#applySortAndLimit().(sortParam, orderParam, limitParam string, offsetParam string) { |
| 220 | l.Sortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Sort. = sortParam |
| 221 | l.Orderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Order. = orderParam |
| 222 | |
| 223 | if l.Orderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Order. == "desc" { |
| 224 | switch l.Sortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Sort. { |
| 225 | case sortByNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByName.: |
| 226 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Reversescip-go gomod github.com/golang/go/src go1.25.1 sort/Reverse().(byNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#(*l))) |
| 227 | case sortByNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByNameDirFirst.: |
| 228 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Reversescip-go gomod github.com/golang/go/src go1.25.1 sort/Reverse().(byNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#(*l))) |
| 229 | case sortBySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortBySize.: |
| 230 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Reversescip-go gomod github.com/golang/go/src go1.25.1 sort/Reverse().(bySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#(*l))) |
| 231 | case sortByTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByTime.: |
| 232 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Reversescip-go gomod github.com/golang/go/src go1.25.1 sort/Reverse().(byTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#(*l))) |
| 233 | } |
| 234 | } else { |
| 235 | switch l.Sortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Sort. { |
| 236 | case sortByNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByName.: |
| 237 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(byNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#(*l)) |
| 238 | case sortByNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByNameDirFirst.: |
| 239 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(byNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#(*l)) |
| 240 | case sortBySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortBySize.: |
| 241 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(bySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#(*l)) |
| 242 | case sortByTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByTime.: |
| 243 | sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Sortscip-go gomod github.com/golang/go/src go1.25.1 sort/Sort().(byTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#(*l)) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | if offsetParam != "" { |
| 248 | offset, _ := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.1 strconv/Atoi().(offsetParam) |
| 249 | if offset > 0 && offset <= len(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.) { |
| 250 | l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items. = l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[offset:] |
| 251 | l.Offsetscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Offset. = offset |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if limitParam != "" { |
| 256 | limit, _ := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.1 strconv/Atoi().(limitParam) |
| 257 | |
| 258 | if limit > 0 && limit <= len(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.) { |
| 259 | l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items. = l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[:limit] |
| 260 | l.Limitscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Limit. = limit |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // crumb represents part of a breadcrumb menu, |
| 266 | // pairing a link with the text to display. |
| 267 | type crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb# struct { |
| 268 | Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link., Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text. string |
| 269 | } |
| 270 | |
| 271 | // fileInfo contains serializable information |
| 272 | // about a file or directory. |
| 273 | type fileInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo# struct { |
| 274 | Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name. string `json:"name"` |
| 275 | Sizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Size. int64 `json:"size"` |
| 276 | URLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#URL. string `json:"url"` |
| 277 | ModTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#ModTime. timescip-go gomod github.com/golang/go/src go1.25.1 time/.Timescip-go gomod github.com/golang/go/src go1.25.1 time/Time# `json:"mod_time"` |
| 278 | Modescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Mode. osscip-go gomod github.com/golang/go/src go1.25.1 os/.FileModescip-go gomod github.com/golang/go/src go1.25.1 os/FileMode# `json:"mode"` |
| 279 | IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. bool `json:"is_dir"` |
| 280 | IsSymlinkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsSymlink. bool `json:"is_symlink"` |
| 281 | SymlinkPathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#SymlinkPath. string `json:"symlink_path,omitempty"` |
| 282 | |
| 283 | // a pointer to the template context is useful inside nested templates |
| 284 | Tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Tpl. *browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext# `json:"-"` |
| 285 | } |
| 286 | |
| 287 | // HasExt returns true if the filename has any of the given suffixes, case-insensitive. |
| 288 | func (fi fileInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#) HasExtscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#HasExt().(exts ...string) bool { |
| 289 | return slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.ContainsFuncscip-go gomod github.com/golang/go/src go1.25.1 slices/ContainsFunc().(exts, func(ext string) bool { |
| 290 | return stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.25.1 strings/HasSuffix().(stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(fi.Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.), stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(ext)) |
| 291 | }) |
| 292 | } |
| 293 | |
| 294 | // HumanSize returns the size of the file as a |
| 295 | // human-readable string in IEC format (i.e. |
| 296 | // power of 2 or base 1024). |
| 297 | func (fi fileInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#) HumanSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#HumanSize().() string { |
| 298 | return humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/.IBytesscip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/IBytes().(uint64(fi.Sizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Size.)) |
| 299 | } |
| 300 | |
| 301 | // HumanTotalFileSize returns the total size of all files |
| 302 | // in the listing as a human-readable string in IEC format |
| 303 | // (i.e. power of 2 or base 1024). |
| 304 | func (btc browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#) HumanTotalFileSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#HumanTotalFileSize().() string { |
| 305 | return humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/.IBytesscip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/IBytes().(uint64(btc.TotalFileSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#TotalFileSize.)) |
| 306 | } |
| 307 | |
| 308 | // HumanTotalFileSizeFollowingSymlinks is the same as HumanTotalFileSize |
| 309 | // except the returned value reflects the size of symlink targets. |
| 310 | func (btc browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#) HumanTotalFileSizeFollowingSymlinksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#HumanTotalFileSizeFollowingSymlinks().() string { |
| 311 | return humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/.IBytesscip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/IBytes().(uint64(btc.TotalFileSizeFollowingSymlinksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#TotalFileSizeFollowingSymlinks.)) |
| 312 | } |
| 313 | |
| 314 | // HumanModTime returns the modified time of the file |
| 315 | // as a human-readable string given by format. |
| 316 | func (fi fileInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#) HumanModTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#HumanModTime().(format string) string { |
| 317 | return fi.ModTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#ModTime..Formatscip-go gomod github.com/golang/go/src go1.25.1 time/Time#Format().(format) |
| 318 | } |
| 319 | |
| 320 | type ( |
| 321 | byNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName# browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext# |
| 322 | byNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst# browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext# |
| 323 | bySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize# browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext# |
| 324 | byTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime# browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext# |
| 325 | ) |
| 326 | |
| 327 | func (l byNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#) Lenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#Len().() int { return len(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.) } |
| 328 | func (l byNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#) Swapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#Swap().(i, j int) { l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j] = l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i] } |
| 329 | |
| 330 | func (l byNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#) Lessscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byName#Less().(i, j int) bool { |
| 331 | return stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.) < stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.) |
| 332 | } |
| 333 | |
| 334 | func (l byNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#) Lenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#Len().() int { return len(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.) } |
| 335 | func (l byNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#) Swapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#Swap().(i, j int) { l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j] = l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i] } |
| 336 | |
| 337 | func (l byNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#) Lessscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byNameDirFirst#Less().(i, j int) bool { |
| 338 | // sort by name if both are dir or file |
| 339 | if l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. == l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. { |
| 340 | return stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.) < stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.) |
| 341 | } |
| 342 | // sort dir ahead of file |
| 343 | return l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. |
| 344 | } |
| 345 | |
| 346 | func (l bySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#) Lenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#Len().() int { return len(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.) } |
| 347 | func (l bySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#) Swapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#Swap().(i, j int) { l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j] = l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i] } |
| 348 | |
| 349 | func (l bySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#) Lessscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/bySize#Less().(i, j int) bool { |
| 350 | const directoryOffset = -1 << 31 // = -math.MinInt32 |
| 351 | |
| 352 | iSize, jSize := l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].Sizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Size., l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].Sizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Size. |
| 353 | |
| 354 | // directory sizes depend on the file system; to |
| 355 | // provide a consistent experience, put them up front |
| 356 | // and sort them by name |
| 357 | if l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. { |
| 358 | iSize = directoryOffset |
| 359 | } |
| 360 | if l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. { |
| 361 | jSize = directoryOffset |
| 362 | } |
| 363 | if l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. && l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].IsDirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#IsDir. { |
| 364 | return stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.) < stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#Name.) |
| 365 | } |
| 366 | |
| 367 | return iSize < jSize |
| 368 | } |
| 369 | |
| 370 | func (l byTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#) Lenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#Len().() int { return len(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.) } |
| 371 | func (l byTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#) Swapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#Swap().(i, j int) { l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j] = l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j], l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i] } |
| 372 | func (l byTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#) Lessscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/byTime#Less().(i, j int) bool { return l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[i].ModTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#ModTime..Beforescip-go gomod github.com/golang/go/src go1.25.1 time/Time#Before().(l.Itemsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Items.[j].ModTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/fileInfo#ModTime.) } |
| 373 | |
| 374 | const ( |
| 375 | sortByNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByName. = "name" |
| 376 | sortByNameDirFirstscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByNameDirFirst. = "namedirfirst" |
| 377 | sortBySizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortBySize. = "size" |
| 378 | sortByTimescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortByTime. = "time" |
| 379 | |
| 380 | sortOrderAscscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortOrderAsc. = "asc" |
| 381 | sortOrderDescscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/sortOrderDesc. = "desc" |
| 382 | ) |