"html/template"
"io/fs"
"os"
+ "path"
"sort"
"time"
IsDir bool
Type string
ModTime string
+ Symlink string
}
func dirList(
cfg *HostCfg,
- dir string,
+ dir, pth string,
entries []os.DirEntry,
readme string,
) (*os.File, error) {
} else {
file.Type = mediaType(file.Name, cfg.MIMEs)
}
+ if (entry.Type() & fs.ModeSymlink) > 0 {
+ file.Symlink, _ = os.Readlink(path.Join(pth, fi.Name()))
+ }
files = append(files, file)
}
fd, err := os.CreateTemp("", "godlist-dirlist-")
<table border=1>
<tr><th> </th><th>Name</th><th>Mtime</th><th>Size</th><th>Type</th></tr>
{{$Dir := .Dir}}{{$Root := .Root}}{{range .Files}}<tr>
- <td>{{.Idx}}</td>
+ <td {{if .Symlink}}rowspan="2"{{end}}>{{.Idx}}</td>
<td><a href="{{$Root}}{{$Dir}}{{.Name}}{{if .IsDir}}/{{end -}}"><tt>
{{- .Name}}{{if .IsDir}}/{{end}}</tt></a></td>
<td><tt>{{.ModTime}}</tt></td>
<td>{{.Size}}</td>
<td><tt>{{if .IsDir}}dir{{else}}{{.Type}}{{end}}</tt></td>
-</tr>
+</tr>{{if .Symlink}}<tr><td colspan="4"><tt>-> {{.Symlink}}</tt></td></tr>{{end}}
{{end -}}
</table>
</body>
// Highly-customizable HTTP, HTTP/2, HTTPS server
package godlighty
-const Version = "godlighty/0.1.0"
+const Version = "godlighty/0.2.0"
var BindAddr string
break
}
}
- fd, err = dirList(cfg, r.URL.Path, entries, string(readme))
+ fd, err = dirList(cfg, r.URL.Path, pth, entries, string(readme))
if err != nil {
printErr(http.StatusInternalServerError, err)
http.Error(w, "internal error", http.StatusInternalServerError)