Documentation
¶
Index ¶
- func Copy(src Medium, srcPath string, dst Medium, dstPath string) error
- func EnsureDir(m Medium, path string) error
- func IsFile(m Medium, path string) bool
- func Read(m Medium, path string) (string, error)
- func Write(m Medium, path, content string) error
- type DirEntry
- type FileInfo
- type Medium
- type MockMedium
- func (m *MockMedium) Delete(path string) error
- func (m *MockMedium) DeleteAll(path string) error
- func (m *MockMedium) EnsureDir(path string) error
- func (m *MockMedium) Exists(path string) bool
- func (m *MockMedium) FileGet(path string) (string, error)
- func (m *MockMedium) FileSet(path, content string) error
- func (m *MockMedium) IsDir(path string) bool
- func (m *MockMedium) IsFile(path string) bool
- func (m *MockMedium) List(path string) ([]fs.DirEntry, error)
- func (m *MockMedium) Read(path string) (string, error)
- func (m *MockMedium) Rename(oldPath, newPath string) error
- func (m *MockMedium) Stat(path string) (fs.FileInfo, error)
- func (m *MockMedium) Write(path, content string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DirEntry ¶
type DirEntry struct {
// contains filtered or unexported fields
}
DirEntry provides a simple implementation of fs.DirEntry for mock testing.
type FileInfo ¶
type FileInfo struct {
// contains filtered or unexported fields
}
FileInfo provides a simple implementation of fs.FileInfo for mock testing.
type Medium ¶
type Medium interface {
// Read retrieves the content of a file as a string.
Read(path string) (string, error)
// Write saves the given content to a file, overwriting it if it exists.
Write(path, content string) error
// EnsureDir makes sure a directory exists, creating it if necessary.
EnsureDir(path string) error
// IsFile checks if a path exists and is a regular file.
IsFile(path string) bool
// FileGet is a convenience function that reads a file from the medium.
FileGet(path string) (string, error)
// FileSet is a convenience function that writes a file to the medium.
FileSet(path, content string) error
// Delete removes a file or empty directory.
Delete(path string) error
// DeleteAll removes a file or directory and all its contents recursively.
DeleteAll(path string) error
// Rename moves a file or directory from oldPath to newPath.
Rename(oldPath, newPath string) error
// List returns the directory entries for the given path.
List(path string) ([]fs.DirEntry, error)
// Stat returns file information for the given path.
Stat(path string) (fs.FileInfo, error)
// Exists checks if a path exists (file or directory).
Exists(path string) bool
// IsDir checks if a path exists and is a directory.
IsDir(path string) bool
}
Medium defines the standard interface for a storage backend. This allows for different implementations (e.g., local disk, S3, SFTP) to be used interchangeably.
var Local Medium
Local is a pre-initialized medium for the local filesystem. It uses "/" as root, providing unsandboxed access to the filesystem. For sandboxed access, use NewSandboxed with a specific root path.
func NewSandboxed ¶
NewSandboxed creates a new Medium sandboxed to the given root directory. All file operations are restricted to paths within the root. The root directory will be created if it doesn't exist.
type MockMedium ¶
MockMedium is an in-memory implementation of Medium for testing.
func NewMockMedium ¶
func NewMockMedium() *MockMedium
NewMockMedium creates a new MockMedium instance.
func (*MockMedium) Delete ¶
func (m *MockMedium) Delete(path string) error
Delete removes a file or empty directory from the mock filesystem.
func (*MockMedium) DeleteAll ¶
func (m *MockMedium) DeleteAll(path string) error
DeleteAll removes a file or directory and all contents from the mock filesystem.
func (*MockMedium) EnsureDir ¶
func (m *MockMedium) EnsureDir(path string) error
EnsureDir records that a directory exists in the mock filesystem.
func (*MockMedium) Exists ¶
func (m *MockMedium) Exists(path string) bool
Exists checks if a path exists in the mock filesystem.
func (*MockMedium) FileGet ¶
func (m *MockMedium) FileGet(path string) (string, error)
FileGet is a convenience function that reads a file from the mock filesystem.
func (*MockMedium) FileSet ¶
func (m *MockMedium) FileSet(path, content string) error
FileSet is a convenience function that writes a file to the mock filesystem.
func (*MockMedium) IsDir ¶
func (m *MockMedium) IsDir(path string) bool
IsDir checks if a path is a directory in the mock filesystem.
func (*MockMedium) IsFile ¶
func (m *MockMedium) IsFile(path string) bool
IsFile checks if a path exists as a file in the mock filesystem.
func (*MockMedium) List ¶
func (m *MockMedium) List(path string) ([]fs.DirEntry, error)
List returns directory entries for the mock filesystem.
func (*MockMedium) Read ¶
func (m *MockMedium) Read(path string) (string, error)
Read retrieves the content of a file from the mock filesystem.
func (*MockMedium) Rename ¶
func (m *MockMedium) Rename(oldPath, newPath string) error
Rename moves a file or directory in the mock filesystem.
func (*MockMedium) Stat ¶
func (m *MockMedium) Stat(path string) (fs.FileInfo, error)
Stat returns file information for the mock filesystem.
func (*MockMedium) Write ¶
func (m *MockMedium) Write(path, content string) error
Write saves the given content to a file in the mock filesystem.