ZDDC/zddc/internal/listing/listing.go
ZDDC ea385b5366 Initial commit
ZDDC — Zero Day Document Control. A file-naming convention plus five
single-file HTML tools (archive, transmittal, classifier, mdedit,
landing) and an optional Go HTTP server (zddc-server) with ACL and a
virtual archive index. Self-contained, offline-capable, dependency-free.

See README.md for an overview, AGENTS.md and ARCHITECTURE.md for the
build/release/architecture detail, bootstrap/README.md for the
two-level deployment install pattern, and zddc/README.md for the
HTTP server.
2026-04-27 11:05:47 -05:00

46 lines
987 B
Go

package listing
import (
"net/url"
"os"
)
// FromDirEntries converts os.DirEntry slice to []FileInfo.
// baseURL is the URL prefix for this directory (must end with "/").
// Hidden files (starting with ".") are excluded.
func FromDirEntries(entries []os.DirEntry, baseURL string) ([]FileInfo, error) {
var result []FileInfo
for _, entry := range entries {
name := entry.Name()
// Skip hidden files and dotfiles
if len(name) == 0 || name[0] == '.' {
continue
}
info, err := entry.Info()
if err != nil {
continue
}
isDir := entry.IsDir()
entryName := name
entryURL := baseURL + url.PathEscape(name)
if isDir {
entryName = name + "/"
entryURL = baseURL + url.PathEscape(name) + "/"
}
fi := FileInfo{
Name: entryName,
Size: info.Size(),
URL: entryURL,
ModTime: info.ModTime(),
Mode: uint32(info.Mode()),
IsDir: isDir,
IsSymlink: false,
}
result = append(result, fi)
}
return result, nil
}