better

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 12 Imported by: 2

README

better

Same, but better

go.dev reference License

github.com/btwiuse/better.FileServer

a drop-in replacement to http.FileServer, with pretty directory listing.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Assets embed.FS

Assets holds the embedded filesystem for the default template

Functions

func AfterEpoch

func AfterEpoch(t time.Time) bool

AfterEpoch returns the time since the epoch for the given time

func FileServer

func FileServer(root http.FileSystem) http.Handler

func GetTemplate

func GetTemplate() (*template.Template, error)

GetTemplate returns the HTML template for serving directories via HTTP/WebDAV

Types

type Crumb

type Crumb struct {
	Link string
	Text string
}

Crumb is a breadcrumb entry

type DirEntry

type DirEntry struct {
	URL     string
	Leaf    string
	IsDir   bool
	Size    int64
	ModTime time.Time
	// contains filtered or unexported fields
}

DirEntry is a directory entry

type Directory

type Directory struct {
	DirRemote    string
	Title        string
	Name         string
	Entries      []DirEntry
	Query        string
	HTMLTemplate *template.Template
	Breadcrumb   []Crumb
	Sort         string
	Order        string
}

Directory represents a directory

func NewDirectory

func NewDirectory(dirRemote string, htmlTemplate *template.Template) *Directory

NewDirectory makes an empty Directory

func (*Directory) AddEntry

func (d *Directory) AddEntry(remote string, isDir bool)

AddEntry adds an entry to that directory

func (*Directory) AddHTMLEntry

func (d *Directory) AddHTMLEntry(remote string, isDir bool, size int64, modTime time.Time)

AddHTMLEntry adds an entry to that directory

func (*Directory) ProcessQueryParams

func (d *Directory) ProcessQueryParams(sortParm string, orderParm string) *Directory

ProcessQueryParams takes and sorts/orders based on the request sort/order parameters and default is namedirfirst/asc

func (*Directory) Serve

func (d *Directory) Serve(w http.ResponseWriter, r *http.Request)

Serve serves a directory

func (*Directory) SetQuery

func (d *Directory) SetQuery(queryParams url.Values) *Directory

SetQuery sets the query parameters for each URL

Jump to

Keyboard shortcuts

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