package storage

import "github.com/oslokommune/okctl/pkg/storage"

Package storage provides an API towards common storage operations

Index

Types

type Cleaner

type Cleaner interface {
	Clean() error
}

Cleaner provides an interface that may be implemented in order to cleanup a store

type EphemeralStorage

type EphemeralStorage struct {
	*Storage
}

EphemeralStorage wraps storage and implements the Cleaner interface

func NewEphemeralStorage

func NewEphemeralStorage() *EphemeralStorage

NewEphemeralStorage will return an in memory file system

func (*EphemeralStorage) Clean

func (e *EphemeralStorage) Clean() error

Clean simply instantiates a new in-memory store

type Storage

type Storage struct {
	BasePath string
	Fs       afero.Fs
}

Storage stores state about the filesystem

func NewFileSystemStorage

func NewFileSystemStorage(path string) *Storage

NewFileSystemStorage will return a store to a base path filesystem

func (*Storage) Abs

func (s *Storage) Abs(name string) string

Abs will return the absolute path to a file

func (*Storage) Create

func (s *Storage) Create(dir, file string, perms os.FileMode) (afero.File, error)

Create will create all directories leading to a file and then the file itself

func (*Storage) Exists

func (s *Storage) Exists(name string) (bool, error)

Exists will determine if a file exists

func (*Storage) MkdirAll

func (s *Storage) MkdirAll(dir string) error

MkdirAll creates a directory and all preceding directories if they do not exist

func (*Storage) Path

func (s *Storage) Path() string

Path returns the base path for the store

func (*Storage) ReadAll

func (s *Storage) ReadAll(path string) ([]byte, error)

ReadAll returns all the content of a file

func (*Storage) Recreate

func (s *Storage) Recreate(dir, file string, perms os.FileMode) (afero.File, error)

Recreate will delete a file and then recreate it

func (*Storage) RemoveAll

func (s *Storage) RemoveAll(path string) error

RemoveAll returns no error if it successfully remove everything under the given path

type StoreCleaner

type StoreCleaner interface {
	Storer
	Cleaner
}

StoreCleaner provides an interface for a store that allows for common read and write operations and wiping everything afterwards

type Storer

type Storer interface {
	Create(dir, name string, perms os.FileMode) (afero.File, error)
	Recreate(dir, file string, perms os.FileMode) (afero.File, error)
	RemoveAll(path string) error
	ReadAll(path string) ([]byte, error)
	MkdirAll(dir string) error
	Exists(name string) (bool, error)
	Abs(name string) string
	Path() string
}

Storer provides an interface for creating and modifying files and directories

type TemporaryStorage

type TemporaryStorage struct {
	*Storage
}

TemporaryStorage wraps Storage and implements the Cleaner interface

func NewTemporaryStorage

func NewTemporaryStorage() (*TemporaryStorage, error)

NewTemporaryStorage creates a new temporary storage

func (*TemporaryStorage) Clean

func (s *TemporaryStorage) Clean() error

Clean removes everything at the path the filesystem was created from

Source Files

storage.go

Version
v0.0.106 (latest)
Published
Oct 21, 2022
Platform
linux/amd64
Imports
4 packages
Last checked
18 hours ago

Tools for package owners.