Documentation ¶
Overview ¶
Package browse provides middleware for listing files in a directory when directory path is requested instead of a specific file.
Index ¶
- Variables
- type ArchiveType
- type Browse
- func (b Browse) ServeArchive(w http.ResponseWriter, r *http.Request, dirPath string, dirInfo os.FileInfo, ...) (int, error)
- func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
- func (b Browse) ServeListing(w http.ResponseWriter, r *http.Request, requestedFilepath http.File, ...) (int, error)
- type Config
- type Crumb
- type FileInfo
- type Listing
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ArchiveTypes = []ArchiveType{ArchiveZip, ArchiveTar, ArchiveTarGz, ArchiveTarXz, ArchiveTarBrotli, ArchiveTarBz2, ArchiveTarLz4, ArchiveTarSz, ArchiveTarZstd} ArchiveTypeToMime = map[ArchiveType]string{ ArchiveZip: "application/zip", ArchiveTar: "application/tar", ArchiveTarGz: "application/tar+gzip", ArchiveTarXz: "application/tar+xz", ArchiveTarBrotli: "application/tar+brotli", ArchiveTarBz2: "application/tar+bzip2", ArchiveTarLz4: "application/tar+lz4", ArchiveTarSz: "application/tar+snappy", ArchiveTarZstd: "application/tar+zstd", } )
Functions ¶
This section is empty.
Types ¶
type ArchiveType ¶ added in v1.2.10
type ArchiveType string
const ( ArchiveZip ArchiveType = "zip" ArchiveTar ArchiveType = "tar" ArchiveTarGz ArchiveType = "tar.gz" ArchiveTarXz ArchiveType = "tar.xz" ArchiveTarBrotli ArchiveType = "tar.br" ArchiveTarBz2 ArchiveType = "tar.bz2" ArchiveTarLz4 ArchiveType = "tar.lz4" ArchiveTarSz ArchiveType = "tar.sz" ArchiveTarZstd ArchiveType = "tar.zst" )
func (ArchiveType) GetWriter ¶ added in v1.2.10
func (a ArchiveType) GetWriter() archiver.Writer
type Browse ¶
type Browse struct { Next httpserver.Handler Configs []Config IgnoreIndexes bool }
Browse is an http.Handler that can show a file listing when directories in the given paths are specified.
func (Browse) ServeArchive ¶ added in v1.2.10
type Config ¶
type Config struct { PathScope string // the base path the URL must match to enable browsing Fs staticfiles.FileServer Variables interface{} Template *template.Template ArchiveTypes []ArchiveType BufferSize uint64 }
Config is a configuration for browsing in a particular path.
type FileInfo ¶
type FileInfo struct { Name string Size int64 URL string ModTime time.Time Mode os.FileMode IsDir bool IsSymlink bool }
FileInfo is the info about a particular file or directory
func (FileInfo) HumanModTime ¶
HumanModTime returns the modified time of the file as a human-readable string.
type Listing ¶
type Listing struct { // The name of the directory (the last element of the path). Name string // The full path of the request. Path string // Whether the parent directory is browse-able. CanGoUp bool // The items (files and folders) in the path. Items []FileInfo // The number of directories in the listing. NumDirs int // The number of files (items that aren't directories) in the listing. NumFiles int // Which sorting order is used. Sort string // And which order. Order string // If ≠0 then Items have been limited to that many elements. ItemsLimitedTo int ArchiveTypes []ArchiveType // Optional custom variables for use in browse templates. User interface{} httpserver.Context }
A Listing is the context used to fill out a template.
func (Listing) Breadcrumbs ¶
Breadcrumbs returns l.Path where every element maps the link to the text to display.
Click to show internal directories.
Click to hide internal directories.