Documentation ¶
Index ¶
- Variables
- type File
- type FileFS
- func (fs FileFS) Dirs() ([]FilePortal, error)
- func (fs FileFS) Get(file string) ([]byte, error)
- func (fs FileFS) Has(file string) bool
- func (fs FileFS) Name() string
- func (fs FileFS) Remove(file string) error
- func (fs FileFS) RemoveAll() error
- func (fs FileFS) Save(file string, data []byte) error
- func (fs FileFS) Within(path string) (FilePortal, error)
- type FileInfo
- type FileMode
- type FilePortal
- type FileSystem
- type GetFile
- type SystemGroup
- type VirtualFile
- func (vf *VirtualFile) Close() error
- func (vf *VirtualFile) IsDir() bool
- func (vf *VirtualFile) ModTime() time.Time
- func (vf *VirtualFile) Mode() FileMode
- func (vf *VirtualFile) Name() string
- func (vf *VirtualFile) Readdir(n int) ([]FileInfo, error)
- func (vf *VirtualFile) Size() int64
- func (vf *VirtualFile) Stat() (FileInfo, error)
- type VirtualFileSystem
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
GetFile define a function type that returns a VirtualFile type or an error.
func StripPrefix ¶
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 ¶
VirtualFile exposes a slice of []byte and associated name as a http.File. It implements http.File interface.
func NewVirtualFile ¶
NewVirtualFile returns a new instance of VirtualFile.
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) 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.