switchfs

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 13 Imported by: 0

README

switchfs

Go Reference Go Report Card CI License

Path-based routing filesystem for the AbsFs ecosystem. Route filesystem operations to different backend implementations based on path patterns.

Overview

switchfs provides intelligent path-based routing to different filesystem backends. It's designed with a single responsibility: route operations based on paths. All other concerns (caching, retry, monitoring, etc.) are handled through composition with other absfs filesystems.

Core Features:

  • Route operations to different backends by path prefix, glob pattern, or regex
  • Support for multiple simultaneous backends (local, cloud, memory, etc.)
  • Transparent operation routing - applications see a unified filesystem
  • Configurable routing rules with priority ordering
  • Cross-backend move/rename with automatic data transfer (files and directories)
  • Conditional routing based on file size, modification time, or custom logic
  • Path rewriting for backend-specific transformations

Design Philosophy:

  • Single Responsibility: switchfs only handles routing logic
  • Composition Over Integration: Use other absfs implementations for caching, retry, monitoring, etc.
  • Clean Separation: Each filesystem wrapper does one thing well

Use Cases

Hybrid Storage

Combine local and cloud storage in a single filesystem view:

localFS, _ := osfs.NewFS("/local/storage")
cloudFS := s3fs.NewFS(s3Config)

fs, _ := switchfs.New(
    switchfs.WithRoute("/workspace/*", localFS, switchfs.WithPriority(100)),
    switchfs.WithRoute("/archive/*", cloudFS, switchfs.WithPriority(100)),
    switchfs.WithDefault(localFS),
)
Tiered Storage

Implement hot/warm/cold storage tiers:

hotFS, _ := memfs.NewFS()           // In-memory for hot data
warmFS := osfs.NewFS("/warm")       // Local SSD for warm data
coldFS := s3fs.NewFS(s3Config)      // S3 for cold data

fs, _ := switchfs.New(
    switchfs.WithRoute("/hot/*", hotFS, switchfs.WithPriority(100)),
    switchfs.WithRoute("/warm/*", warmFS, switchfs.WithPriority(50)),
    switchfs.WithRoute("/cold/*", coldFS, switchfs.WithPriority(10)),
)
Multi-Cloud Architecture

Route to different cloud providers by path:

fs, _ := switchfs.New(
    switchfs.WithRoute("/aws/*", s3FS, switchfs.WithPriority(100)),
    switchfs.WithRoute("/gcp/*", gcsFS, switchfs.WithPriority(100)),
    switchfs.WithRoute("/azure/*", azureFS, switchfs.WithPriority(100)),
)

Composition Examples

The power of switchfs comes from composing it with other absfs filesystems. Here are common patterns:

Example 1: Routing + Caching + Retry + Metrics
import (
    "github.com/absfs/switchfs"
    "github.com/absfs/cachefs"
    "github.com/absfs/retryfs"
    "github.com/absfs/metricsfs"
    "github.com/absfs/memfs"
    "github.com/absfs/osfs"
)

// Create backends
localFS, _ := memfs.NewFS()
remoteFS := s3fs.NewFS(s3Config)

// Layer 1: Route based on paths
router, _ := switchfs.New(
    switchfs.WithRoute("/local/*", localFS, switchfs.WithPriority(100)),
    switchfs.WithRoute("/remote/*", remoteFS, switchfs.WithPriority(100)),
    switchfs.WithDefault(localFS),
)

// Layer 2: Add caching (use cachefs to cache routing decisions and file metadata)
cached := cachefs.New(router, cachefs.WithLRU(1000), cachefs.WithTTL(5*time.Minute))

// Layer 3: Add retry logic (retryfs handles transient failures)
retry := retryfs.New(cached,
    retryfs.WithMaxAttempts(3),
    retryfs.WithExponentialBackoff(100*time.Millisecond, 5*time.Second),
)

// Layer 4: Add metrics collection (metricsfs tracks operations)
metrics := metricsfs.New(retry,
    metricsfs.WithPrometheus(),
    metricsfs.WithOpenTelemetry(),
)

// Use the fully composed filesystem
fs := metrics
file, _ := fs.Open("/remote/data.txt")
Example 2: Routing with Read-Only Enforcement
import (
    "github.com/absfs/switchfs"
    "github.com/absfs/rofs"
)

// Create backends
writeFS := osfs.NewFS("/writable")
readOnlyFS := s3fs.NewFS(s3Config)

// Make the S3 backend explicitly read-only
roFS := rofs.New(readOnlyFS)

// Route with mixed read/write permissions
fs, _ := switchfs.New(
    switchfs.WithRoute("/work/*", writeFS),
    switchfs.WithRoute("/archive/*", roFS),  // Read-only archived data
)
Example 3: Conditional Routing + Compression
import (
    "github.com/absfs/switchfs"
    "github.com/absfs/compressfs"
)

// Large files go to compressed cloud storage
largeFilesFS := compressfs.New(s3FS, compressfs.WithZstd())
smallFilesFS := localFS

fs, _ := switchfs.New(
    // Route large files (>10MB) to compressed cloud storage
    switchfs.WithRoute("/**/*", largeFilesFS,
        switchfs.WithCondition(switchfs.SizeGreaterThan(10*1024*1024)),
        switchfs.WithPriority(100),
        switchfs.WithPatternType(switchfs.PatternGlob),
    ),
    // Everything else to local storage
    switchfs.WithDefault(smallFilesFS),
)
Example 4: Path Rewriting
import (
    "github.com/absfs/switchfs"
)

// Backend stores files with different path structure
backend := s3fs.NewFS(s3Config)

fs, _ := switchfs.New(
    // Rewrite /api/v1/files/* to /production/files/* in backend
    switchfs.WithRoute("/api/v1/files/*", backend,
        switchfs.WithRewriter(switchfs.NewPrefixRewriter("/api/v1/files", "/production/files")),
    ),
)

// Write to /api/v1/files/data.txt
// Actually stored as /production/files/data.txt in S3
file, _ := fs.Create("/api/v1/files/data.txt")
Example 5: Encrypted Cloud Storage with Local Cache
import (
    "github.com/absfs/switchfs"
    "github.com/absfs/encryptfs"
    "github.com/absfs/cachefs"
    "github.com/absfs/unionfs"
)

// Encrypt data before sending to cloud
cloudFS := s3fs.NewFS(s3Config)
encryptedCloud := encryptfs.New(cloudFS, encryptfs.WithAES256GCM(key))

// Local cache for faster access
localCache, _ := memfs.NewFS()

// Union: check local cache first, fall back to encrypted cloud
unified := unionfs.New(localCache, encryptedCloud, unionfs.WithCopyOnWrite())

// Route sensitive data through encrypted cloud
publicFS := osfs.NewFS("/public")

fs, _ := switchfs.New(
    switchfs.WithRoute("/sensitive/*", unified),
    switchfs.WithRoute("/public/*", publicFS),
)

API Design

Basic Types
// Route defines a routing rule
type Route struct {
    Pattern   string              // Path pattern (prefix, glob, or regex)
    Backend   absfs.FileSystem    // Target backend filesystem
    Priority  int                 // Higher priority routes match first
    Type      PatternType         // Prefix, Glob, or Regex
    Failover  absfs.FileSystem    // Optional backup backend
    Condition RouteCondition      // Optional condition for routing
    Rewriter  PathRewriter        // Optional path transformation
}

// PatternType defines how patterns are matched
type PatternType int

const (
    PatternPrefix PatternType = iota  // Simple prefix match "/data/*"
    PatternGlob                        // Glob pattern "**/*.txt"
    PatternRegex                       // Regular expression "^/user/[0-9]+/.*"
)
Configuration
// Option configures SwitchFS behavior
type Option func(*SwitchFS) error

// WithDefault sets the default backend for unmatched paths
func WithDefault(fs absfs.FileSystem) Option

// WithRoute adds a routing rule
func WithRoute(pattern string, backend absfs.FileSystem, opts ...RouteOption) Option

// RouteOption configures individual routes
type RouteOption func(*Route) error

// WithPriority sets route priority (higher matches first)
func WithPriority(priority int) RouteOption

// WithPatternType sets the pattern matching type
func WithPatternType(pt PatternType) RouteOption

// WithFailover sets a failover backend
func WithFailover(fs absfs.FileSystem) RouteOption

// WithCondition sets a routing condition
func WithCondition(condition RouteCondition) RouteOption

// WithRewriter sets a path rewriter
func WithRewriter(rewriter PathRewriter) RouteOption

Routing Features

1. Prefix Matching (Default)
fs, _ := switchfs.New(
    switchfs.WithRoute("/data", backend),
)
// Matches: /data, /data/file.txt, /data/subdir/file.txt
2. Glob Patterns
fs, _ := switchfs.New(
    // Match all .txt files
    switchfs.WithRoute("**/*.txt", textBackend,
        switchfs.WithPatternType(switchfs.PatternGlob)),

    // Match cache directories anywhere
    switchfs.WithRoute("**/.cache/*", cacheBackend,
        switchfs.WithPatternType(switchfs.PatternGlob)),
)
3. Regex Patterns
fs, _ := switchfs.New(
    // Match user-specific paths /user/123/files/*
    switchfs.WithRoute(`^/user/[0-9]+/`, userBackend,
        switchfs.WithPatternType(switchfs.PatternRegex)),
)
4. Priority Ordering
fs, _ := switchfs.New(
    // Specific pattern with high priority
    switchfs.WithRoute("/data/cache/*", cacheBackend,
        switchfs.WithPriority(100)),

    // Broader pattern with lower priority
    switchfs.WithRoute("/data/*", dataBackend,
        switchfs.WithPriority(50)),
)
// /data/cache/file.txt -> routes to cacheBackend (priority 100)
// /data/other/file.txt -> routes to dataBackend (priority 50)
5. Conditional Routing
// Route based on file size
fs, _ := switchfs.New(
    switchfs.WithRoute("/**/*", largeFileBackend,
        switchfs.WithCondition(switchfs.SizeGreaterThan(100*1024*1024)),
        switchfs.WithPatternType(switchfs.PatternGlob),
        switchfs.WithPriority(100)),
    switchfs.WithDefault(normalBackend),
)

// Custom conditions
fs, _ := switchfs.New(
    switchfs.WithRoute("/**/*", archiveBackend,
        switchfs.WithCondition(switchfs.OlderThan(365*24*time.Hour)),
        switchfs.WithPatternType(switchfs.PatternGlob)),
)
6. Path Rewriting
// Strip prefix
rewriter := switchfs.NewPrefixRewriter("/api/v1", "")
fs, _ := switchfs.New(
    switchfs.WithRoute("/api/v1/*", backend,
        switchfs.WithRewriter(rewriter)),
)
// /api/v1/file.txt -> stored as /file.txt in backend

// Replace prefix
rewriter := switchfs.NewPrefixRewriter("/old", "/new")
// /old/file.txt -> stored as /new/file.txt
7. Failover Support
primaryBackend := s3fs.NewFS(primaryConfig)
backupBackend := s3fs.NewFS(backupConfig)

fs, _ := switchfs.New(
    switchfs.WithRoute("/critical/*", primaryBackend,
        switchfs.WithFailover(backupBackend)),
)
// If primary fails, automatically tries backup

Cross-Backend Operations

File Moves
fs, _ := switchfs.New(
    switchfs.WithRoute("/src/*", backend1),
    switchfs.WithRoute("/dst/*", backend2),
)

// Move file across backends - automatic copy + delete
fs.Rename("/src/file.txt", "/dst/file.txt")
Directory Moves
// Recursively move entire directory tree across backends
fs.Rename("/src/directory", "/dst/directory")
// Automatically copies all files and subdirectories, then removes source
Same-Backend Optimization
// When source and destination use the same backend, native rename is used
fs.Rename("/src/file1.txt", "/src/file2.txt")  // Fast native rename

Available Conditions

Built-in routing conditions:

// Size-based routing
switchfs.SizeGreaterThan(bytes int64)
switchfs.SizeLessThan(bytes int64)
switchfs.SizeBetween(min, max int64)

// Time-based routing
switchfs.ModifiedAfter(t time.Time)
switchfs.ModifiedBefore(t time.Time)
switchfs.OlderThan(duration time.Duration)
switchfs.NewerThan(duration time.Duration)

// Custom conditions
type RouteCondition interface {
    Evaluate(path string, info os.FileInfo) bool
}

Available Rewriters

Built-in path rewriters:

// Prefix replacement
switchfs.NewPrefixRewriter(oldPrefix, newPrefix string)

// Custom rewriters
type PathRewriter interface {
    Rewrite(path string) string
}

Composition Patterns

Pattern: Caching Layer
router := switchfs.New(...)
cached := cachefs.New(router, opts...)  // Cache on top of routing
Pattern: Retry + Routing
router := switchfs.New(...)
retry := retryfs.New(router, opts...)  // Retry failed operations
Pattern: Metrics + Everything
// Always put metrics at the outermost layer
router := switchfs.New(...)
cached := cachefs.New(router, opts...)
retry := retryfs.New(cached, opts...)
metrics := metricsfs.New(retry, opts...)  // Metrics wraps everything
Pattern: Encryption for Specific Routes
// Encrypt only cloud storage, not local
localFS := osfs.NewFS("/local")
cloudFS := s3fs.NewFS(s3Config)
encryptedCloud := encryptfs.New(cloudFS, opts...)

router := switchfs.New(
    switchfs.WithRoute("/local/*", localFS),
    switchfs.WithRoute("/cloud/*", encryptedCloud),
)

Performance Considerations

Routing Performance
  • Route lookup is O(n) where n = number of routes
  • Routes are sorted by priority at registration time
  • Glob patterns are compiled once
  • Regex patterns are compiled and cached
  • Use cachefs to cache routing decisions for frequently accessed paths
Cross-Backend Operations
  • Move/rename across backends requires data copy
  • Large file transfers use streaming (constant memory)
  • Directory moves are recursive but efficient
  • For better performance, organize routes to minimize cross-backend moves
Optimization Strategies
  • Put most frequently accessed routes first (high priority)
  • Use prefix patterns when possible (faster than glob/regex)
  • Compose with cachefs to cache backend lookups
  • Use retryfs for unreliable backends (cloud, network)
  • Use metricsfs to identify performance bottlenecks

Thread Safety

All operations are thread-safe:

  • Route registration/removal uses read-write locks
  • Concurrent operations routed independently
  • Backend-specific concurrency handled by backends
  • No shared state between routed operations

Error Handling

var (
    ErrNoRoute               // No route matches the path
    ErrNilBackend           // Nil backend provided
    ErrInvalidPattern       // Invalid route pattern
    ErrDuplicateRoute       // Route pattern already exists
    ErrCrossBackendOperation // Operation spans backends (legacy)
)

Testing

import "testing"
import "github.com/absfs/memfs"

func TestRouting(t *testing.T) {
    backend1, _ := memfs.NewFS()
    backend2, _ := memfs.NewFS()

    fs, _ := switchfs.New(
        switchfs.WithRoute("/b1/*", backend1),
        switchfs.WithRoute("/b2/*", backend2),
    )

    // Test routing
    fs.Create("/b1/file.txt")  // Goes to backend1
    fs.Create("/b2/file.txt")  // Goes to backend2
}

Dependencies

github.com/absfs/absfs                    - Core filesystem interfaces
github.com/bmatcuk/doublestar/v4         - Glob pattern matching
Optional Composition Partners
github.com/absfs/osfs      - Local filesystem
github.com/absfs/memfs     - In-memory filesystem
github.com/absfs/s3fs      - Amazon S3 backend
github.com/absfs/cachefs   - Caching layer
github.com/absfs/retryfs   - Retry logic with exponential backoff
github.com/absfs/metricsfs - Prometheus and OpenTelemetry metrics
github.com/absfs/compressfs - Transparent compression
github.com/absfs/encryptfs  - Transparent encryption
github.com/absfs/rofs       - Read-only wrapper
github.com/absfs/lockfs     - Thread-safe wrapper
github.com/absfs/unionfs    - Union/overlay filesystem
github.com/absfs/permfs     - Permission and ACL enforcement

Contributing

Contributions welcome! Please ensure:

  • All tests pass (go test ./...)
  • Code follows Go conventions
  • New features include tests and documentation
  • Focus on routing-specific functionality (compose for other features)

License

MIT License - see LICENSE file

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoRoute is returned when no route matches the given path
	ErrNoRoute = errors.New("no route found for path")

	// ErrAllBackendsFailed is returned when both primary and failover backends fail
	ErrAllBackendsFailed = errors.New("all backends failed")

	// ErrCrossBackendOperation is returned for unsupported operations that span multiple backends
	ErrCrossBackendOperation = errors.New("operation spans multiple backends")

	// ErrInvalidPattern is returned when a route pattern is invalid
	ErrInvalidPattern = errors.New("invalid route pattern")

	// ErrDuplicateRoute is returned when attempting to add a route with an existing pattern
	ErrDuplicateRoute = errors.New("route with pattern already exists")

	// ErrNilBackend is returned when a nil backend is provided
	ErrNilBackend = errors.New("backend cannot be nil")
)

Functions

This section is empty.

Types

type Option

type Option func(*SwitchFS) error

Option configures SwitchFS behavior

func WithDefault

func WithDefault(backend absfs.FileSystem) Option

WithDefault sets the default backend for unmatched paths

func WithRoute

func WithRoute(pattern string, backend absfs.FileSystem, opts ...RouteOption) Option

WithRoute adds a routing rule

func WithRouter

func WithRouter(router Router) Option

WithRouter sets a custom router implementation

func WithTempDir

func WithTempDir(dir string) Option

WithTempDir sets the temporary directory path

type PathRewriter

type PathRewriter interface {
	// Rewrite transforms a path according to route rules
	Rewrite(path string) string
}

PathRewriter rewrites/transforms paths for a route

func AddPrefix

func AddPrefix(prefix string) PathRewriter

AddPrefix creates a rewriter that adds a prefix to paths

func ChainRewriters

func ChainRewriters(rewriters ...PathRewriter) PathRewriter

ChainRewriters creates a rewriter that applies multiple rewriters in order

Example
// Create a chain that transforms paths
chain := ChainRewriters(
	StripPrefix("/virtual"),
	AddPrefix("/real/storage"),
)

// /virtual/file.txt -> /real/storage/file.txt
result := chain.Rewrite("/virtual/file.txt")
_ = result // Use result

func RegexRewrite

func RegexRewrite(pattern, replacement string) (PathRewriter, error)

RegexRewrite creates a rewriter that uses regex patterns

func ReplacePrefix

func ReplacePrefix(oldPrefix, newPrefix string) PathRewriter

ReplacePrefix creates a rewriter that replaces one prefix with another

func StaticMapping

func StaticMapping(mapping map[string]string) PathRewriter

StaticMapping creates a rewriter with a static path mapping

func StripPrefix

func StripPrefix(prefix string) PathRewriter

StripPrefix creates a rewriter that removes a prefix from paths

type PatternType

type PatternType int

PatternType defines how patterns are matched

const (
	// PatternPrefix matches by simple prefix
	PatternPrefix PatternType = iota
	// PatternGlob matches using glob patterns
	PatternGlob
	// PatternRegex matches using regular expressions
	PatternRegex
)

func (PatternType) String

func (pt PatternType) String() string

String returns the string representation of PatternType

type Route

type Route struct {
	// Pattern is the path pattern (prefix, glob, or regex)
	Pattern string

	// Backend is the target backend filesystem
	Backend absfs.FileSystem

	// Priority determines match order (higher priority routes match first)
	Priority int

	// Type specifies how the pattern should be matched
	Type PatternType

	// Failover is an optional backup backend
	Failover absfs.FileSystem

	// Condition is an optional condition that must be met for routing
	Condition RouteCondition

	// Rewriter optionally transforms paths before passing to backend
	Rewriter PathRewriter
	// contains filtered or unexported fields
}

Route defines a routing rule

type RouteCondition

type RouteCondition interface {
	// Evaluate returns true if the condition is met for the given file info
	Evaluate(path string, info os.FileInfo) bool
}

RouteCondition evaluates whether a route should match based on file metadata

func And

func And(conditions ...RouteCondition) RouteCondition

And combines multiple conditions - all must be true

func DirectoriesOnly

func DirectoriesOnly() RouteCondition

DirectoriesOnly creates a condition that matches only directories

func FilesOnly

func FilesOnly() RouteCondition

FilesOnly creates a condition that matches only files (not directories)

func MaxSize

func MaxSize(bytes int64) RouteCondition

MaxSize creates a condition that matches files <= maxSize bytes

func MinSize

func MinSize(bytes int64) RouteCondition

MinSize creates a condition that matches files >= minSize bytes

func ModifiedBetween

func ModifiedBetween(start, end time.Time) RouteCondition

ModifiedBetween creates a condition that matches files modified within a time range

func NewerThan

func NewerThan(t time.Time) RouteCondition

NewerThan creates a condition that matches files modified after the given time

func Not

func Not(condition RouteCondition) RouteCondition

Not inverts a condition

func OlderThan

func OlderThan(t time.Time) RouteCondition

OlderThan creates a condition that matches files modified before the given time

func Or

func Or(conditions ...RouteCondition) RouteCondition

Or combines multiple conditions - at least one must be true

func SizeRange

func SizeRange(minBytes, maxBytes int64) RouteCondition

SizeRange creates a condition that matches files within a size range

type RouteOption

type RouteOption func(*Route) error

RouteOption configures individual routes

func WithCondition

func WithCondition(condition RouteCondition) RouteOption

WithCondition sets a condition that must be met for routing

Example
backend, _ := memfs.NewFS()

// Route only large files to this backend
_, _ = New(
	WithRoute("/data", backend,
		WithPriority(100),
		WithCondition(MinSize(1024*1024)), // Files >= 1MB
	),
)

func WithFailover

func WithFailover(backend absfs.FileSystem) RouteOption

WithFailover sets a failover backend

func WithPatternType

func WithPatternType(pt PatternType) RouteOption

WithPatternType sets the pattern matching type

func WithPriority

func WithPriority(priority int) RouteOption

WithPriority sets route priority

func WithRewriter

func WithRewriter(rewriter PathRewriter) RouteOption

WithRewriter sets a path rewriter for the route

type Router

type Router interface {
	// AddRoute adds a routing rule
	AddRoute(route Route) error

	// RemoveRoute removes a routing rule by pattern
	RemoveRoute(pattern string) error

	// Route finds the backend for a given path
	Route(path string) (absfs.FileSystem, error)

	// RouteWithInfo finds the route for a given path with file info for condition evaluation
	RouteWithInfo(path string, info os.FileInfo) (*Route, error)

	// Routes returns all registered routes
	Routes() []Route
}

Router manages routing decisions

func NewRouter

func NewRouter() Router

NewRouter creates a new router instance

type SwitchFS

type SwitchFS struct {
	// contains filtered or unexported fields
}

SwitchFS implements absfs.FileSystem with routing

func New

func New(opts ...Option) (*SwitchFS, error)

New creates a new SwitchFS with the given options

Example
backend1, _ := memfs.NewFS()
backend2, _ := memfs.NewFS()

// Create SwitchFS with multiple backends
fs, _ := New(
	WithRoute("/hot", backend1, WithPriority(100)),
	WithRoute("/cold", backend2, WithPriority(50)),
)

// Files under /hot go to backend1
f, _ := fs.Create("/hot/cache.dat")
f.Write([]byte("cached data"))
f.Close()

// Files under /cold go to backend2
f, _ = fs.Create("/cold/archive.dat")
f.Write([]byte("archived data"))
f.Close()

func (*SwitchFS) Chdir

func (fs *SwitchFS) Chdir(dir string) error

Chdir changes the current working directory

func (*SwitchFS) Chmod

func (fs *SwitchFS) Chmod(name string, mode os.FileMode) error

Chmod changes file permissions

func (*SwitchFS) Chown

func (fs *SwitchFS) Chown(name string, uid, gid int) error

Chown changes file owner and group

func (*SwitchFS) Chtimes

func (fs *SwitchFS) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes file access and modification times

func (*SwitchFS) Create

func (fs *SwitchFS) Create(name string) (absfs.File, error)

Create creates a new file

func (*SwitchFS) Getwd

func (fs *SwitchFS) Getwd() (string, error)

Getwd returns the current working directory

func (*SwitchFS) Mkdir

func (fs *SwitchFS) Mkdir(name string, perm os.FileMode) error

Mkdir creates a directory

func (*SwitchFS) MkdirAll

func (fs *SwitchFS) MkdirAll(name string, perm os.FileMode) error

MkdirAll creates a directory and all parent directories

func (*SwitchFS) Open

func (fs *SwitchFS) Open(name string) (absfs.File, error)

Open opens a file for reading

func (*SwitchFS) OpenFile

func (fs *SwitchFS) OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error)

OpenFile opens a file with the specified flags and permissions

func (*SwitchFS) ReadDir

func (fs *SwitchFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory and returns a list of directory entries

func (*SwitchFS) ReadFile

func (fs *SwitchFS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns its contents

func (*SwitchFS) Remove

func (fs *SwitchFS) Remove(name string) error

Remove removes a file or empty directory

func (*SwitchFS) RemoveAll

func (fs *SwitchFS) RemoveAll(path string) error

RemoveAll removes a path and all children

func (*SwitchFS) Rename

func (fs *SwitchFS) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath

func (*SwitchFS) Router

func (fs *SwitchFS) Router() Router

Router returns the underlying router for advanced usage

func (*SwitchFS) Stat

func (fs *SwitchFS) Stat(name string) (os.FileInfo, error)

Stat returns file information

func (*SwitchFS) Sub

func (fs *SwitchFS) Sub(dir string) (fs.FS, error)

Sub returns a Filer corresponding to the subtree rooted at dir

func (*SwitchFS) TempDir

func (fs *SwitchFS) TempDir() string

TempDir returns the temporary directory

func (*SwitchFS) Truncate

func (fs *SwitchFS) Truncate(name string, size int64) error

Truncate changes the size of a file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL