tree

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contexter

type Contexter interface {
	// Retruns a copy of the http.File with the given context for IO operations.
	WithContext(context.Context) http.File
}

type FS

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

FS implements https://godoc.org/net/http#FileSystem over a Tree.

func NewFS

func NewFS(tree Tree) *FS

func (FS) Open

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

Open is the implementation of http.FileSystem over a Tree.

func (FS) WithContext

func (fs FS) WithContext(ctx context.Context) *FS

WithContext returns a copy of filesystem with the given context. This context will be applied for open operations.

type Loader

type Loader func(context.Context) ([]byte, error)

Loader is a function that loads file content. If the context id done this function should return an error.

type Opener

type Opener interface {
	// Open returns a file/dir.
	Open() http.File
	// Stat returns information about the file/dir.
	Stat() (os.FileInfo, error)
	// Readdir retruns list of file info contained in a directory.
	// Preforming Readdir on a file returns nil, nil.
	Readdir(count int) ([]os.FileInfo, error)
}

Opener is an interface for a directory or a file provider.

type Tree

type Tree map[string]Opener

Tree maps a file path to a file provider.

func (Tree) AddDir

func (t Tree) AddDir(path string) error

AddDir adds a directory to a tree. It also adds recursively all the parent directories.

func (Tree) AddFile

func (t Tree) AddFile(path string, size int, load Loader) error

AddFile adds a file to a tree. It also adds recursively all the parent directories.

Jump to

Keyboard shortcuts

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