serve

package
v1.76.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 15 Imported by: 25

Documentation

Overview

Package serve deals with serving objects over HTTP

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(ctx context.Context, what any, w http.ResponseWriter, text string, err error)

Error logs the error and if a ResponseWriter is given it writes an http.StatusInternalServerError

func Object

func Object(w http.ResponseWriter, r *http.Request, o fs.Object)

Object serves an fs.Object via HEAD or GET

Types

type Crumb

type Crumb struct {
	Link string
	Text string
}

Crumb is a breadcrumb entry

type DirEntry

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

DirEntry is a directory entry

type Directory

type Directory struct {
	DirRemote    string
	Title        string
	Name         string
	ZipURL       string
	DisableZip   bool
	Entries      []DirEntry
	Query        string
	HTMLTemplate *template.Template
	Breadcrumb   []Crumb
	Sort         string
	Order        string
	Static       bool   // rendering for a static site, so no "up" link at the root
	LinkIndex    string // if set, appended to directory links, e.g. "index.html"
}

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) IsRoot added in v1.76.0

func (d *Directory) IsRoot() bool

IsRoot returns true if this is the root directory

func (*Directory) NumDirs added in v1.76.0

func (d *Directory) NumDirs() (n int)

NumDirs returns the number of directory entries

func (*Directory) NumFiles added in v1.76.0

func (d *Directory) NumFiles() int

NumFiles returns the number of file entries

func (*Directory) Path added in v1.76.0

func (d *Directory) Path() string

Path returns the path of the directory from the root with leading and trailing slashes, e.g. "/dir/" or "/" for the root.

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) Render added in v1.76.0

func (d *Directory) Render(w io.Writer) error

Render writes the directory listing to w using the HTML template

func (*Directory) Serve

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

Serve serves a directory

func (*Directory) SetLinkIndex added in v1.76.0

func (d *Directory) SetLinkIndex(name string) *Directory

SetLinkIndex makes directory links point at name inside the directory, e.g. "dir/index.html" rather than "dir/", for hosts which don't serve index documents. Call it before adding entries.

func (*Directory) SetQuery

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

SetQuery sets the query parameters for each URL

func (*Directory) TotalSize added in v1.76.0

func (d *Directory) TotalSize() (size int64)

TotalSize returns the total size of the file entries

func (d *Directory) UpLink() string

UpLink returns the link to the parent directory

Jump to

Keyboard shortcuts

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