Created
August 1, 2015 14:19
-
-
Save alapidas/85c437df9502818c0090 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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