Complete API documentation for all packages in digital.vasic.filesystem.
Import: digital.vasic.filesystem/pkg/client
Defines the core interfaces and types used across all protocol adapters. This package has zero external dependencies.
The primary abstraction for filesystem operations. All protocol adapters implement this interface.
type Client interface {
Connect(ctx context.Context) error
Disconnect(ctx context.Context) error
IsConnected() bool
TestConnection(ctx context.Context) error
ReadFile(ctx context.Context, path string) (io.ReadCloser, error)
WriteFile(ctx context.Context, path string, data io.Reader) error
GetFileInfo(ctx context.Context, path string) (*FileInfo, error)
FileExists(ctx context.Context, path string) (bool, error)
DeleteFile(ctx context.Context, path string) error
CopyFile(ctx context.Context, srcPath, dstPath string) error
ListDirectory(ctx context.Context, path string) ([]*FileInfo, error)
CreateDirectory(ctx context.Context, path string) error
DeleteDirectory(ctx context.Context, path string) error
GetProtocol() string
GetConfig() interface{}
}Establishes the connection to the storage backend. Must be called before any file or directory operations.
- Local: Validates that
BasePathexists and is a directory. - SMB: Opens TCP connection, performs NTLM auth, mounts share.
- FTP: Dials server with 30s timeout, logs in, changes to base directory.
- NFS: Creates mount point directory, calls
syscall.Mount. - WebDAV: Sends
PROPFINDwithDepth: 0to verify server.
Closes the connection and releases resources.
- Local: No-op (sets connected flag to false).
- SMB: Unmounts share, logs off session, closes TCP connection. Collects all errors.
- FTP: Sends
QUITcommand. - NFS: Calls
syscall.Unmount. - WebDAV: No-op (sets connected flag to false).
Returns whether the client is currently connected. Operations fail with "not connected" if this returns false.
Verifies the connection is still alive.
- Local:
os.Staton base path. - SMB:
ReadDir(".")on the share. - FTP:
CurrentDir()call. - NFS:
os.Staton mount point. - WebDAV: Re-performs
Connect().
Opens a file for reading. The caller is responsible for closing the returned io.ReadCloser.
- path: Relative path within the storage backend.
- Returns: An
io.ReadCloserwrapping the file data.
Writes data to a file. Creates the file if it does not exist, overwrites if it does. Some adapters auto-create parent directories (local, FTP, NFS).
- path: Relative path within the storage backend.
- data: Reader providing the file content.
Returns metadata about a file or directory.
- path: Relative path within the storage backend.
- Returns:
*FileInfowith name, size, modification time, directory flag, permissions, and path.
Checks whether a file or directory exists. Returns (false, nil) for missing files rather than an error.
Deletes a single file.
Copies a file from source to destination within the same storage backend.
- WebDAV: Uses the HTTP
COPYmethod withDestinationheader. - FTP: Downloads source, uploads to destination.
- Local/NFS: Opens source, creates destination,
io.Copy. - SMB: Opens source, creates destination,
io.Copy.
Lists all entries in a directory.
- path: Relative path to the directory. Use
""or"."for the root. - Returns: Slice of
*FileInfofor each entry. Does not include.or...
Creates a directory. Local and NFS adapters create intermediate directories (MkdirAll). SMB creates a single directory level.
Deletes a directory. Local and NFS adapters remove contents recursively (RemoveAll). SMB and FTP require the directory to be empty.
Returns the protocol identifier string: "smb", "ftp", "nfs", "webdav", or "local".
Returns the protocol-specific configuration struct. Cast to the appropriate type:
smbConfig := c.GetConfig().(*smb.Config)
localConfig := c.GetConfig().(*local.Config)Creates Client instances from StorageConfig.
type Factory interface {
CreateClient(config *StorageConfig) (Client, error)
SupportedProtocols() []string
}Creates a new client for the protocol specified in config.Protocol. Returns an error for unsupported protocols.
Returns the list of supported protocol identifiers.
Manages a pool of reusable client connections. Defined for future implementation.
type ConnectionPool interface {
GetClient(config *StorageConfig) (Client, error)
ReturnClient(client Client) error
CloseAll() error
}Represents metadata about a file or directory.
type FileInfo struct {
Name string // Base name of the file
Size int64 // Size in bytes (0 for directories on some protocols)
ModTime time.Time // Last modification time
IsDir bool // True if the entry is a directory
Mode os.FileMode // Unix permissions (0644 default for remote protocols)
Path string // Relative path within the storage backend
}Configuration for creating a storage client through the factory.
type StorageConfig struct {
ID string `json:"id"` // Unique identifier
Name string `json:"name"` // Human-readable name
Protocol string `json:"protocol"` // Protocol: smb, ftp, nfs, webdav, local
Enabled bool `json:"enabled"` // Whether the storage is active
MaxDepth int `json:"max_depth"` // Max directory traversal depth
Settings map[string]interface{} `json:"settings"` // Protocol-specific configuration
CreatedAt time.Time `json:"created_at"` // Creation timestamp
UpdatedAt time.Time `json:"updated_at"` // Last update timestamp
}Describes a file copy request.
type CopyOperation struct {
SourcePath string // Source file path
DestinationPath string // Destination file path
OverwriteExisting bool // Whether to overwrite if destination exists
}Describes the outcome of a copy operation.
type CopyResult struct {
Success bool // Whether the copy succeeded
BytesCopied int64 // Number of bytes copied
Error error // Error if copy failed
TimeTaken time.Duration // Duration of the operation
}Import: digital.vasic.filesystem/pkg/factory
Provides the DefaultFactory implementation of client.Factory and helper functions for extracting typed values from settings maps.
type DefaultFactory struct{}Implements client.Factory. Routes protocol strings to the appropriate adapter constructor.
Creates a new factory instance.
f := factory.NewDefaultFactory()Creates a protocol-specific client based on config.Protocol:
| Protocol | Adapter Created |
|---|---|
"smb" |
smb.NewSMBClient |
"ftp" |
ftp.NewFTPClient |
"nfs" |
nfs.NewNFSClient (Linux) or error (other platforms) |
"webdav" |
webdav.NewWebDAVClient |
"local" |
local.NewLocalClient |
Returns fmt.Errorf("unsupported protocol: %s", config.Protocol) for unknown protocols.
Returns []string{"smb", "ftp", "nfs", "webdav", "local"}.
func NewSMBClient(config *smb.Config) client.ClientConvenience wrapper that delegates to smb.NewSMBClient.
func GetStringSetting(settings map[string]interface{}, key, defaultValue string) stringExtracts a string value from a settings map. Returns defaultValue if the key is missing or the value is not a string.
func GetIntSetting(settings map[string]interface{}, key string, defaultValue int) intExtracts an integer value from a settings map. Handles both int and float64 types (JSON numbers deserialize as float64). Returns defaultValue if the key is missing or the value is not numeric.
Import: digital.vasic.filesystem/pkg/smb
SMB/CIFS protocol adapter using the go-smb2 library.
type Config struct {
Host string `json:"host"` // Server hostname or IP
Port int `json:"port"` // Server port (typically 445)
Share string `json:"share"` // Share name
Username string `json:"username"` // NTLM username
Password string `json:"password"` // NTLM password
Domain string `json:"domain"` // Windows domain (e.g., "WORKGROUP")
}type Client struct { /* unexported fields */ }Implements client.Client. Internal fields: conn (TCP connection), session (smb2.Session), share (smb2.Share), config.
Creates a new SMB client. Does not connect; call Connect() to establish the connection.
Import: digital.vasic.filesystem/pkg/ftp
FTP protocol adapter using the jlaffaye/ftp library.
type Config struct {
Host string `json:"host"` // Server hostname or IP
Port int `json:"port"` // Server port (typically 21)
Username string `json:"username"` // FTP username
Password string `json:"password"` // FTP password
Path string `json:"path"` // Base directory on the server
}type Client struct { /* unexported fields */ }Implements client.Client. Internal fields: config, client (goftp.ServerConn), connected.
Creates a new FTP client. Does not connect; call Connect() to establish the connection.
Connection timeout: 30 seconds (hardcoded in goftp.DialWithTimeout).
Import: digital.vasic.filesystem/pkg/nfs
Platform: Linux only (//go:build linux)
NFS protocol adapter using syscall.Mount/syscall.Unmount.
type Config struct {
Host string `json:"host"` // NFS server hostname or IP
Path string `json:"path"` // Exported path on the server
MountPoint string `json:"mount_point"` // Local directory to mount on
Options string `json:"options"` // Mount options (default: "vers=3")
}type Client struct { /* unexported fields */ }Implements client.Client. Internal fields: config, mounted, connected, mountPoint.
Creates a new NFS client. Returns an error if MountPoint is empty. Note: this constructor takes Config by value (not pointer), unlike other adapters.
Privileges: Connect() calls syscall.Mount, which typically requires root.
Import: digital.vasic.filesystem/pkg/webdav
WebDAV protocol adapter using net/http for HTTP-based file operations.
type Config struct {
URL string `json:"url"` // WebDAV server base URL
Username string `json:"username"` // HTTP Basic Auth username (optional)
Password string `json:"password"` // HTTP Basic Auth password (optional)
Path string `json:"path"` // Path prefix on the server
}type Client struct { /* unexported fields */ }Implements client.Client. Internal fields: config, client (http.Client with 30s timeout), baseURL (url.URL), connected.
Creates a new WebDAV client. Parses the URL and applies the path prefix. Does not connect; call Connect() to verify server accessibility.
HTTP Methods Used:
| Operation | HTTP Method |
|---|---|
| Connect / TestConnection | PROPFIND (Depth: 0) |
| ReadFile | GET |
| WriteFile | PUT |
| GetFileInfo | HEAD |
| ListDirectory | PROPFIND (Depth: 1) |
| FileExists | HEAD |
| CreateDirectory | MKCOL |
| DeleteFile / DeleteDirectory | DELETE |
| CopyFile | COPY (with Destination header) |
ListDirectory response parsing: Parses the DAV XML multistatus response using string splitting on <D:response> elements. Extracts href, displayname, getcontentlength, getlastmodified, and resourcetype properties.
Import: digital.vasic.filesystem/pkg/local
Local filesystem adapter using the Go os package.
type Config struct {
BasePath string `json:"base_path"` // Absolute path to the base directory
}type Client struct { /* unexported fields */ }Implements client.Client. Internal fields: config, basePath, connected.
Creates a new local filesystem client. Does not validate the path; call Connect() to verify the base directory exists.
Path resolution: All relative paths are joined with BasePath after cleaning and stripping .. sequences. This prevents path traversal outside the base directory.
Auto-creation: WriteFile and CopyFile automatically create parent directories using os.MkdirAll. CreateDirectory also creates intermediate directories.
DeleteDirectory: Uses os.RemoveAll, which recursively deletes all contents.
All adapter Client types satisfy client.Client at compile time via interface compliance declarations:
// In pkg/local/local_test.go
var _ client.Client = (*Client)(nil)
// In pkg/factory/factory_test.go
var _ client.Factory = (*DefaultFactory)(nil)