Documentation ¶
Index ¶
- func FileServer(root Dir, useIndex bool, readOnly bool, tmpl *template.Template) http.Handler
- func Main()
- func NewArea(x, y, w, h int) *area
- func SaveAuthToken(configPath, authtoken string) (err error)
- func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, ...)
- type Configuration
- type Dir
- type Directory
- type File
- type FileSystem
- type Options
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileServer ¶
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 SaveAuthToken ¶
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 http.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.
Types ¶
type Configuration ¶
type Configuration struct {
AuthToken string `yaml:"authtoken,omitempty"`
}
func LoadConfiguration ¶
func LoadConfiguration(path string) (config *Configuration, err error)
type Dir ¶
type Dir string
A Dir implements http.FileSystem using the native file system restricted to a specific directory tree.
An empty Dir is treated as ".".
type File ¶
type File interface { Close() error Stat() (os.FileInfo, error) Readdir(count int) ([]os.FileInfo, error) Read([]byte) (int, error) Seek(offset int64, whence int) (int64, error) }
A File is returned by a FileSystem's Open method and can be served by the FileServer implementation.
type FileSystem ¶
A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.