Skip to content

Instantly share code, notes, and snippets.

@alapidas
Created August 1, 2015 14:19
Show Gist options
  • Save alapidas/85c437df9502818c0090 to your computer and use it in GitHub Desktop.
Save alapidas/85c437df9502818c0090 to your computer and use it in GitHub Desktop.
/*
The filesystem package provides a unified interface to a real backed filesystem.
An example use case for this might be a server that wants serve up directory
listings/information and provide CRUD access to a filesystem.
*/
package filesystem
import (
trie "github.com/tchap/go-patricia/patricia"
"os"
)
// A TransientFilesystemer represents an in-memory representation of a filesystem.
type TransientFilesystemer interface {
Filesystemer
Sync() error
}
// Filesystemer is the base interface that any filesystem should implement.
type Filesystemer interface {
PathExists(path string) bool
MkPath(path string) error
RmPath(path string) error // Applies to both paths + files
MkFile(path string, content []byte, perms os.FileMode) error
GetFile(path string) (*os.File, error)
}
type TransientFilesystem struct {
*trie.Trie
RootPath string
}
type PassThroughFilesystem struct {
RootPath string
}
var _ Filesystemer = (*PassThroughFilesystem)(nil)
var _ TransientFilesystemer = (*TransientFilesystemer)(nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment