filesystem

package
v0.0.0-...-df570b3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExist       = errors.New("Path exists")
	ErrNotExist    = errors.New("Path does not exists")
	ErrToManyParts = errors.New("Prefix must contain only two parts: /bob/log")
)

errors ...

Functions

This section is empty.

Types

type File

type File interface {
	io.Closer
	io.Reader
	io.Seeker
	Readdir(count int) ([]FileInfo, error)
	Stat() (FileInfo, error)
}

File defines a interface for representing a file.

type FileFS

type FileFS struct {
	Dir string
}

FileFS implements a simple store for storing and retrieving file from underneath filesystem.

func (FileFS) Dirs

func (fs FileFS) Dirs() ([]FilePortal, error)

Dirs returns all top level directory in file.

func (FileFS) Get

func (fs FileFS) Get(file string) ([]byte, error)

Get retrieves giving file path within FileFS.Dir.

func (FileFS) Has

func (fs FileFS) Has(file string) bool

Has return true/false if giving file exists in directory of fs.

func (FileFS) Name

func (fs FileFS) Name() string

Name returns underline name of giving FS.

func (FileFS) Remove

func (fs FileFS) Remove(file string) error

Remove deletes giving file path within FileFS.Dir.

func (FileFS) RemoveAll

func (fs FileFS) RemoveAll() error

RemoveAll removes all files within FileFS.Dir and contents.

func (FileFS) Save

func (fs FileFS) Save(file string, data []byte) error

Save saves giving file into FileFS.Dir, overwriting any same file existing.

func (FileFS) Within

func (fs FileFS) Within(path string) (FilePortal, error)

Within returns a new FilePortal which exists within the current path. It enforces all operations to occur within provided path.

type FileInfo

type FileInfo interface {
	Name() string
	Size() int64
	ModTime() time.Time
	IsDir() bool
}

FileInfo defines an interface representing a file into.

type FileMode

type FileMode uint32

FileMode defines the mode value of a file.

type FilePortal

type FilePortal interface {
	Name() string
	Has(string) bool
	RemoveAll() error
	Remove(string) error
	Dirs() ([]FilePortal, error)
	Save(string, []byte) error
	Get(string) ([]byte, error)
	Within(string) (FilePortal, error)
}

FilePortal defines an error which exposes methods to treat a underline store has a file system.

type FileSystem

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

FileSystem defines a interface for a virutal filesystem representing a file.

func New

func New(fn GetFile) FileSystem

New returns a new instance of a VirtualFileSystem as a FileSystem type.

type GetFile

type GetFile func(string) (File, error)

GetFile define a function type that returns a VirtualFile type or an error.

func StripPrefix

func StripPrefix(prefix string, from GetFile) GetFile

StripPrefix returns a new GetFile which wraps the previous provided GetFile and always strips provided prefix from incoming path.

type SystemGroup

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

SystemGroup allows the combination of multiple filesystem to respond to incoming request based on initial path prefix.

func NewSystemGroup

func NewSystemGroup() *SystemGroup

NewSystemGroup returns a new instance of SystemGroup.

func (*SystemGroup) MustRegister

func (fs *SystemGroup) MustRegister(prefix string, m FileSystem) *SystemGroup

MustRegister will panic if the prefix and FileSystem failed to register It returns itself if successfully to allow chaining.

func (*SystemGroup) Open

func (fs *SystemGroup) Open(path string) (File, error)

Open attempts to locate giving path from different file systems, else returning error.

func (*SystemGroup) Register

func (fs *SystemGroup) Register(prefix string, m FileSystem) error

Register adds giving file system to handling paths with given prefix.

type VirtualFile

type VirtualFile struct {
	*bytes.Reader
	FileName string
	FileSize int64
	FileMod  time.Time
}

VirtualFile exposes a slice of []byte and associated name as a http.File. It implements http.File interface.

func NewVirtualFile

func NewVirtualFile(r *bytes.Reader, filename string, size int64, mod time.Time) *VirtualFile

NewVirtualFile returns a new instance of VirtualFile.

func (*VirtualFile) Close

func (vf *VirtualFile) Close() error

Close returns nothing.

func (*VirtualFile) IsDir

func (vf *VirtualFile) IsDir() bool

IsDir returns false because this is a virtual file.

func (*VirtualFile) ModTime

func (vf *VirtualFile) ModTime() time.Time

ModTime returns associated mode time for file.

func (*VirtualFile) Mode

func (vf *VirtualFile) Mode() FileMode

Mode returns associated file mode of file.

func (*VirtualFile) Name

func (vf *VirtualFile) Name() string

Name returns filename of giving file, either as a absolute or relative path.

func (*VirtualFile) Readdir

func (vf *VirtualFile) Readdir(n int) ([]FileInfo, error)

Readdir returns nil slices as this is a file not a directory.

func (*VirtualFile) Size

func (vf *VirtualFile) Size() int64

Size returns data file size.

func (*VirtualFile) Stat

func (vf *VirtualFile) Stat() (FileInfo, error)

Stat returns VirtualFile which implements os.FileInfo for virtual file to meet http.File interface.

type VirtualFileSystem

type VirtualFileSystem struct {
	GetFileFunc GetFile
}

VirtualFileSystem connects a series of functions which are provided to retrieve bundled files and serve to a http server. It implements http.FileSystem interface.

func (VirtualFileSystem) Open

func (v VirtualFileSystem) Open(name string) (File, error)

Open returns associated file with given name if found else returning an error. It implements http.FileSystem.Open method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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