package filesystem import ( "fmt" "html" "io/fs" "path" "path/filepath" "sort" "strings" "github.com/gofiber/fiber/v3" ) func getFileExtension(p string) string { n := strings.LastIndexByte(p, '.') if n < 0 { return "" } return p[n:] } func dirList(c fiber.Ctx, f fs.File) error { ff := f.(fs.ReadDirFile) fileinfos, err := ff.ReadDir(-1) if err != nil { return fmt.Errorf("failed to read dir: %w", err) } fm := make(map[string]fs.FileInfo, len(fileinfos)) filenames := make([]string, 0, len(fileinfos)) for _, fi := range fileinfos { name := fi.Name() info, err := fi.Info() if err != nil { return err } fm[name] = info filenames = append(filenames, name) } basePathEscaped := html.EscapeString(c.Path()) _, _ = fmt.Fprintf(c, "%s", basePathEscaped) _, _ = fmt.Fprintf(c, "

%s

", basePathEscaped) _, _ = fmt.Fprint(c, "") c.Type("html") return nil } func openFile(filesystem fs.FS, name string) (fs.File, error) { name = filepath.ToSlash(name) return filesystem.Open(name) }