Documentation
¶
Overview ¶
Package filebrowser implements a GitHub-like file browser for Caddy v2.
It serves a directory listing with a rendered README and opens text, code, Markdown, image, PDF, audio and video files in an in-page preview dialog.
Index ¶
- type FileBrowser
- func (FileBrowser) CaddyModule() caddy.ModuleInfo
- func (fb *FileBrowser) Provision(ctx caddy.Context) error
- func (fb *FileBrowser) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
- func (fb *FileBrowser) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (fb *FileBrowser) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileBrowser ¶
type FileBrowser struct {
// Root is the directory to serve. It defaults to the site root set by the
// Caddyfile `root` directive. Placeholders are expanded per request.
Root string `json:"root,omitempty"`
// Hide lists file or directory names/patterns that are neither listed nor
// directly accessible. Patterns use path.Match syntax and are matched
// against each path segment, or against the whole relative path when the
// pattern contains a slash. Defaults: .git .env .DS_Store Thumbs.db
// node_modules __pycache__.
Hide []string `json:"hide,omitempty"`
// Readme lists the file names checked, in order, for the README card.
// Matching is case-insensitive and only applies to files directly inside
// the browsed directory. Defaults: README.md README.markdown README readme.md.
Readme []string `json:"readme,omitempty"`
// PreviewMaxSize limits how much text is read for the preview dialog and
// the README. Larger files are listed and can be downloaded, but previews
// are truncated. Default: 1 MiB.
PreviewMaxSize int64 `json:"preview_max_size,omitempty"`
// BrowseLimit caps the number of entries rendered in one directory.
// Default: 10000, maximum: 100000.
BrowseLimit int `json:"browse_limit,omitempty"`
Logger *zap.Logger `json:"-"`
// contains filtered or unexported fields
}
FileBrowser is an HTTP handler that renders a browsable directory with a README and an in-page file preview.
func (FileBrowser) CaddyModule ¶
func (FileBrowser) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*FileBrowser) Provision ¶
func (fb *FileBrowser) Provision(ctx caddy.Context) error
Provision initializes defaults and the Markdown renderer.
func (*FileBrowser) ServeHTTP ¶
func (fb *FileBrowser) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
ServeHTTP implements caddyhttp.MiddlewareHandler.
func (*FileBrowser) UnmarshalCaddyfile ¶
func (fb *FileBrowser) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile parses:
filebrowser {
root <path>
hide <names/patterns...>
readme <file names...>
preview_max_size <size>
browse_limit <n>
}
The root defaults to the site root set by the Caddyfile `root` directive. `hide` with no arguments disables all hiding; `readme` with no arguments is an error because that would disable the README card unintentionally.
func (*FileBrowser) Validate ¶
func (fb *FileBrowser) Validate() error
Validate checks bounds and that README names are plain file names.

