client

package
v0.0.0-...-551e163 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2016 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileServer

func FileServer(root Dir, useIndex bool, readOnly bool, tmpl *template.Template) 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 Main

func Main()

func NewArea

func NewArea(x, y, w, h int) *area

func SaveAuthToken

func SaveAuthToken(configPath, authtoken string) (err error)

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 ".".

func (Dir) Open

func (d Dir) Open(name string) (File, error)

func (Dir) Remove

func (d Dir) Remove(name string) error

func (Dir) Write

func (d Dir) Write(name string, contents io.Reader) error

type Directory

type Directory struct {
	// contains filtered or unexported fields
}

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

type FileSystem interface {
	Open(name string) (File, error)
}

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.

type Options

type Options struct {
	// contains filtered or unexported fields
}

type Route

type Route struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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