caddy: github.com/mholt/caddy/caddyhttp/browse Index | Files

package browse

import "github.com/mholt/caddy/caddyhttp/browse"

Package browse provides middleware for listing files in a directory when directory path is requested instead of a specific file.

Index

Package Files

browse.go setup.go

type Browse Uses

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) ServeHTTP Uses

func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP determines if the request is for this plugin, and if all prerequisites are met. If so, control is handed over to ServeListing.

func (Browse) ServeListing Uses

func (b Browse) ServeListing(w http.ResponseWriter, r *http.Request, requestedFilepath http.File, bc *Config) (int, error)

ServeListing returns a formatted view of 'requestedFilepath' contents'.

type Config Uses

type Config struct {
    PathScope string // the base path the URL must match to enable browsing
    Fs        staticfiles.FileServer
    Variables interface{}
    Template  *template.Template
}

Config is a configuration for browsing in a particular path.

type Crumb Uses

type Crumb struct {
    Link, Text string
}

Crumb represents part of a breadcrumb menu.

type FileInfo Uses

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 Uses

func (fi FileInfo) HumanModTime(format string) string

HumanModTime returns the modified time of the file as a human-readable string.

func (FileInfo) HumanSize Uses

func (fi FileInfo) HumanSize() string

HumanSize returns the size of the file as a human-readable string in IEC format (i.e. power of 2 or base 1024).

type Listing Uses

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

    // 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 Uses

func (l Listing) Breadcrumbs() []Crumb

Breadcrumbs returns l.Path where every element maps the link to the text to display.

Package browse imports 17 packages (graph) and is imported by 108 packages. Updated 2019-07-24. Refresh now. Tools for package owners.