filesystem

package
v0.0.0-...-edcd0ba Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

The filesystem package provides an http.FileSystem implementation that may contain file data not present in the host operating system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem struct {
	// Fallback instructs the filesystem to fall back to the operating system
	// if a file hasn't beed aded to it.
	Fallback bool
	// contains filtered or unexported fields
}

A FileSystem is used to store and access file data. It implements the http.FileSystem interface to be used effortlessly with a FileServer handler.

Since all file data can be provided as a string literal in the Go source, such entries can be effectively embedded into the resultant binary.

func New

func New() *FileSystem

New creates a fresh instance of a FileSystem

func (*FileSystem) Add

func (fs *FileSystem) Add(
	name string, size int64, mode os.FileMode, modTime time.Time, data string,
) error

Add inserts a new named file representation into the filesystem. The size, mode and modTime parameters represent it's byte length, mode bits, and modification time, respectively. The file data is represented as a string, which is usually created using the fmt package's '%q' verb.

If the file name represents a relative path, it will be converted to an absolute path where it's base directory is root of the filesystem. E.g.:

relative/path		->	/relative/path
./relative/path		->	/relative/path
/absolute/path		->	/absolute/path

func (*FileSystem) Open

func (fs *FileSystem) Open(name string) (http.File, error)

Opens a previously inserted named file. If such a file hasn't been added, it may optionally fall back to accessing the file with the same path in the operating system.

Jump to

Keyboard shortcuts

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