A flexible, extensible filesystem abstraction for Go inspired by PHP's Flysystem.
- Unified interface for local, S3, and FTP filesystems
- Easily add your own adapters (e.g., GCS, Azure, custom)
- Consistent API for file operations: read, write, delete, move, copy, list, etc.
- Supports advanced features: visibility, checksums, mime type detection, and more
- Copy and move files between different adapters (even with different config types)
- Well-tested and production-ready
go get gitlab.com/tbhaxor/gofsxpackage main
import (
"fmt"
"gitlab.com/tbhaxor/gofsx"
"gitlab.com/tbhaxor/gofsx/adapters"
)
// Local adapter
localAdapter, err := adapters.NewLocalAdapter("/tmp", nil)
if err != nil {
panic(err)
}
// List files from local adapter
if files, err := localAdapter.ListContents(ctx, ".", true); err != nil {
panic(err)
} else {
fmt.Println(files)
}gofsx is built on a set of small, composable interfaces:
type Readable interface {
Read(ctx context.Context, path string) ([]byte, error)
}
type Writable[TWriteConfig any] interface {
Write(ctx context.Context, path string, content []byte, config *TWriteConfig) error
}
type Deletable interface {
Delete(ctx context.Context, path string, recurse bool) error
}
type Movable interface {
Readable
Deletable
}
type Adapter[TClient, TWriteConfig, TPublicUrlConfig, TTemporaryUrlConfig any] interface {
Writable[TWriteConfig]
Readable
Deletable
// ...plus advanced methods (see code)
}To add your own adapter, implement the relevant interfaces for your backend.
You can copy or move files between any two adapters, even if their config types differ:
// Copy a file across adapters
err := gofsx.CopyBetweenAdapter(ctx, srcAdapter, "foo.txt", dstAdapter, "bar.txt", &dstAdapterWriteConfig)
// Move a file across adapters
err := gofsx.MoveBetweenAdapter(ctx, srcAdapter, "foo.txt", dstAdapter, "bar.txt", &dstAdapterWriteConfig)- Local adapter
- S3 adapter
- FTP adapter
- Google Cloud Storage adapter
- Azure Blob Storage adapter
Contributions are welcome! Please open issues or pull requests for new adapters, bug fixes, or improvements.
MIT License