server

package
v0.0.0-...-c097366 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirectoryHandler

func DirectoryHandler(dir string) (http.HandlerFunc, error)

DirectoryHandler produces an http handler function that can serve the contents of a specified directory. The handler will only serve files that have a matching mime type for their extension. The handler assumes that the path / translates to /index.html and that paths without an extension also map to the .html extension.

func LoadAllResources

func LoadAllResources(dir string) (map[string]*Resource, error)

LoadAllResources recursively walks a directory searching for files that have a supported mime type for http and loads the contents. A URL path is generated from the path relative to the specified directory. The retuned map maps the generated URLs to the loaded resources.

Types

type Resource

type Resource struct {
	FileName string
	Content  []byte
	ModTime  time.Time
}

A Resource is a file loaded from disk

func LoadResource

func LoadResource(path string) (*Resource, error)

LoadResource loads a Resource from a specified file path

func (*Resource) HandleRequest

func (res *Resource) HandleRequest(w http.ResponseWriter, r *http.Request)

HandleRequest returns the resource for a given http GET or HEAD request

Jump to

Keyboard shortcuts

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