fileserver

package
v0.0.0-...-a57c790 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(w http.ResponseWriter, req *http.Request, error string, code int)

Error is the function to call when there is an error. If an ErrorHandler has been specified that will be used. Otherwise it falls back to http.Error.

func FileServer

func FileServer(root http.FileSystem) http.Handler

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

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

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

func NotFound

func NotFound(w http.ResponseWriter, req *http.Request)

NotFound is the function to call when there is a 404 not found response. If a NotFoundHandler has been specified that will be used. The default is http.NotFound.

func ServeContent

func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker)

ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Modified-Since requests.

If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.

If modtime is not the zero time, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.

The content's Seek method must work: ServeContent uses a seek to the end of the content to determine its size.

If the caller has set w's ETag header, ServeContent uses it to handle requests using If-Range and If-None-Match.

Note that *os.File implements the io.ReadSeeker interface.

func ServeFile

func ServeFile(w http.ResponseWriter, r *http.Request, name string)

ServeFile replies to the request with the contents of the named file or directory.

Types

type DirListFunc

type DirListFunc func(http.ResponseWriter, http.File)

DirListFunc is the type for the package variable DirListHandler

var DirListHandler DirListFunc

DirListHandler is the package wide callback function to handle directory listings. The default is the go implementation

type ErrorHandlerFunc

type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, string, int)

ErrorHandlerFunc is the type for the package variable ErrorHandler.

var ErrorHandler ErrorHandlerFunc

ErrorHandler is the package wide callback function to handle file server error responses. The default is http.Error.

type NotFoundFunc

type NotFoundFunc func(http.ResponseWriter, *http.Request)

NotFoundFunc is the type for the package variable NotFoundHandler.

var NotFoundHandler NotFoundFunc

NotFoundHandler is the package wide callback function to handle 404 not found responses. The default is http.NotFound.

Jump to

Keyboard shortcuts

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