gofs

package module
v0.0.0-...-eb3fa9a Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: MIT Imports: 8 Imported by: 0

README

GoFS

The name may be misleading, but it means a file system for the Go runtime, not a file system implemented in Go.

GoFS provides multiple implementations of a generic file system interface that is aimed at the Go runtime not an operational system file system.

Why

This project is the consolidation of 3 different implementations of the same idea (AKA duplication), a way to abstract common storage operations. Basically:

  • Read files
  • Write files
  • Delete files

For testing purposes we required in-memory and host file system implementations, in production we used Amazon S3. Them the day came where we needed to migrate all our storage implementations to Azure. This seemed like a good sign that it was time to remove the duplication and consolidate the library.

We provide a common interface to access the following storages:

  • In Memory
  • Local
  • Amazon S3
  • Azure Blob Storage

The file system interface has a smaller surface than a usual file system since we don't need all operations and some cloud services simply won't provide all those operations for blob storage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

type FS interface {
	ReaderFS
	WriterFS

	// Remove removes the provided path from the underlying storage.
	Remove(path string) error
}

FS is the interface that groups all file system operations

type LocalFS

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

func NewLocalFS

func NewLocalFS(basedir string) *LocalFS

NewLocalFS creates a new LocalFS where all files are opened and created relative to the basedir provided. Very much like a chroot on the provided basedir.

func (*LocalFS) Create

func (l *LocalFS) Create(path string) (io.WriteCloser, error)

func (*LocalFS) Open

func (l *LocalFS) Open(path string) (io.ReadCloser, error)

func (*LocalFS) ReadAll

func (l *LocalFS) ReadAll(path string) ([]byte, error)

func (*LocalFS) Remove

func (l *LocalFS) Remove(path string) error

func (*LocalFS) WriteAll

func (l *LocalFS) WriteAll(path string, contents []byte) error

type MemFS

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

func NewMemFS

func NewMemFS() *MemFS

func (*MemFS) Create

func (m *MemFS) Create(path string) (io.WriteCloser, error)

func (*MemFS) Open

func (m *MemFS) Open(path string) (io.ReadCloser, error)

func (*MemFS) ReadAll

func (m *MemFS) ReadAll(path string) ([]byte, error)

func (*MemFS) Remove

func (m *MemFS) Remove(path string) error

func (*MemFS) WriteAll

func (m *MemFS) WriteAll(path string, contents []byte) error

type ReaderFS

type ReaderFS interface {
	// Open opens the provided path for reading
	Open(path string) (io.ReadCloser, error)

	// ReadAll opens the path for reading and reads all its contents
	// returning them as an byte array.
	ReadAll(path string) ([]byte, error)
}

ReaderFS is the interface that groups the basic Read file system methods.

type WriterFS

type WriterFS interface {
	// Create creates the provided path as a file ready for writing.
	// If the file already exists the file will be truncated.
	Create(path string) (io.WriteCloser, error)

	// Create creates the provided path as a file ready for writing
	// and writes all the contents to it, closing it afterwards.
	WriteAll(path string, contents []byte) error
}

WriterFS is the interface that groups the basic Read file system methods.

Jump to

Keyboard shortcuts

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