fileserver

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

README

fileserver

A modified version of the FileServer() handler found in Go's net/http stdlib. Allows users to customize the resulting markup that's served when browsing a directory.

LICENSE

(BSD)[LICENSE]

Documentation

Overview

Package fileserver implements a modified version of the stdlib net/http FileServer, allowing for custom markup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileServer

func FileServer(
	root http.FileSystem,
	errHandler func(http.ResponseWriter, *http.Request, int, error),
	dirListHandler func(http.ResponseWriter, *http.Request, []FileEntry),
) *fileHandler

FileServer returns a handler that serves HTTP requests with the contents of the file system rooted at root.

As a special case, the returned file server redirects any request ending in "/index.html" to the same path, without the final "index.html".

To use the operating system's file system implementation, use http.Dir:

http.Handle("/", FileServer(http.Dir("/tmp")))

This has been modified from the implementation found in stdlib's net/http to allow for custom markup instead of the hardcoded markup.

Types

type FileEntry

type FileEntry struct {
	URL  string
	Name string
}

FileEntry contains metadata for a file found in a filesystem.

Jump to

Keyboard shortcuts

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