browse

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2015 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var IndexPages = []string{
	"index.html",
	"index.htm",
	"index.txt",
	"default.html",
	"default.htm",
	"default.txt",
}

Functions

This section is empty.

Types

type Browse

type Browse struct {
	Next    middleware.Handler
	Root    string
	Configs []Config
}

Browse is an http.Handler that can show a file listing when directories in the given paths are specified.

func (Browse) ServeHTTP

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

ServeHTTP implements the middleware.Handler interface.

type Config added in v0.6.0

type Config struct {
	PathScope string
	Template  *template.Template
}

Config is a configuration for browsing in a particular path.

type FileInfo

type FileInfo struct {
	IsDir   bool
	Name    string
	Size    int64
	URL     string
	ModTime time.Time
	Mode    os.FileMode
}

FileInfo is the info about a particular file or directory

func (FileInfo) HumanModTime

func (fi FileInfo) HumanModTime(format string) string

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

func (FileInfo) HumanSize

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

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 browsable
	CanGoUp bool

	// The items (files and folders) in the path
	Items []FileInfo

	// Which sorting order is used
	Sort string

	// And which order
	Order string

	middleware.Context
}

A Listing is used to fill out a template.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL