Help us shape the future of Go! Take the 2026 Go Developer Survey

fs

package
v2.0.0-alpha.57 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReadOnly          = errors.New("filesystem is read-only")
	ErrNotFound          = errors.New("filesystem not found in context")
	ErrRootNotConfigured = errors.New("filesystem root is not configured")
)

Functions

func WithFileSystem

func WithFileSystem(ctx context.Context, fs FileSystem) context.Context

WithFileSystem adds FileSystem to context.

Types

type Directories

type Directories interface {
	Mkdir(path string, perm fs.FileMode) error
	MkdirAll(path string, perm fs.FileMode) error
}

func DirectoriesFrom

func DirectoriesFrom(ctx context.Context) (Directories, error)

DirectoriesFrom gets Directories from context.

type FileSystem

type FileSystem interface {
	Reader
	Directories
	Writer
	Remover
	io.Closer
}

FileSystem combines file reading, directory operations, writing, removal, and lifecycle management. The caller owns every FileSystem returned by New and must close it when it is no longer needed.

func FileSystemFrom

func FileSystemFrom(ctx context.Context) (FileSystem, error)

FileSystemFrom gets FileSystem from context.

func New

func New(setters ...Option) (FileSystem, error)

New creates a filesystem from the provided options. The caller owns the returned filesystem and must close it when it is no longer needed.

type Option

type Option = options.Option[config]

func WithReadOnly

func WithReadOnly(readOnly bool) Option

func WithRoot

func WithRoot(root string) Option

type ReadableFile

type ReadableFile interface {
	fs.File
}

type Reader

type Reader interface {
	ReadFile(path string) ([]byte, error)
	Open(path string) (ReadableFile, error)
	OpenFile(path string, flag int, perm fs.FileMode) (WritableFile, error)
	Stat(path string) (fs.FileInfo, error)
	Lstat(path string) (fs.FileInfo, error)
	Exists(path string) (bool, error)
}

func ReaderFrom

func ReaderFrom(ctx context.Context) (Reader, error)

ReaderFrom gets Reader from context.

type Remover

type Remover interface {
	Remove(path string) error
	RemoveAll(path string) error
}

func RemoverFrom

func RemoverFrom(ctx context.Context) (Remover, error)

RemoverFrom gets Remover from context.

type WritableFile

type WritableFile interface {
	ReadableFile
	io.Writer
	io.Seeker
}

type Writer

type Writer interface {
	WriteFile(path string, data []byte, perm fs.FileMode) error
	AppendFile(path string, data []byte, perm fs.FileMode) error
}

func WriterFrom

func WriterFrom(ctx context.Context) (Writer, error)

WriterFrom gets Writer from context.

Jump to

Keyboard shortcuts

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