storage

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package storage can be used for writing and reading files from storage buckets within external object stores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessMode

type AccessMode uint8

AccessMode is use to determine the access mode a file is opened with.

const (
	// ReadOnly mode will open a file as read only.
	// ReadOnly is the default access mode.
	ReadOnly AccessMode = iota

	// WriteOnly mode will open a file for writing only.
	WriteOnly

	// ReadWrite mode will open a file for reading and writing.
	ReadWrite
)

type Bucket

type Bucket interface {
	boundary.Resource
	GetScopeId() string
	GetBucketName() string
	GetBucketPrefix() string
	GetWorkerFilter() string
}

Bucket is a resource that represents a bucket in an external object store

type Container

type Container interface {
	io.Closer
	Create(context.Context, string) (File, error)
	OpenFile(context.Context, string, ...Option) (File, error)
	SubContainer(context.Context, string, ...Option) (Container, error)
}

A Container is a filesystem abstraction that can create files or other containers.

type FS

type FS interface {
	New(ctx context.Context, name string) (Container, error)
	Open(ctx context.Context, name string) (Container, error)
}

FS is a filesystem for creating or reading files and containers.

type File

type File interface {
	fs.File
	io.Writer
	io.StringWriter
}

File represents a storage File.

type Option

type Option func(*Options)

Option is a storage option.

func WithCloseSyncMode

func WithCloseSyncMode(m SyncMode) Option

WithCloseSyncMode sets how a file is synced when closed.

func WithCreateFile

func WithCreateFile() Option

WithCreateFile indicates a file should be created when opening.

func WithFileAccessMode

func WithFileAccessMode(m AccessMode) Option

WithFileAccessMode sets the access mode when a file is opened.

type Options

type Options struct {
	WithCloseSyncMode  SyncMode
	WithFileAccessMode AccessMode
	WithCreateFile     bool
}

Options are storage options.

func GetOpts

func GetOpts(opt ...Option) Options

GetOpts - iterate the inbound Options and return a struct.

type RecordingStorage

type RecordingStorage interface {
	// NewSyncingFS returns an FS that will use local storage as a cache and sync files when they are closed.
	NewSyncingFS(ctx context.Context, bucket *storagebuckets.StorageBucket, _ ...Option) (FS, error)

	// NewRemoteFS returns a ReadOnly FS that can be used to retrieve files from a storage bucket.
	NewRemoteFS(ctx context.Context, bucket *storagebuckets.StorageBucket, _ ...Option) (FS, error)

	// PluginClients returns a map of storage plugin clients keyed on the plugin name.
	PluginClients() map[string]plgpb.StoragePluginServiceClient

	// CreateTemp creates a temporary file that is cleaned up when closed. All temp files
	// are also removed when storage is initialized.
	CreateTemp(ctx context.Context, p string) (TempFile, error)
}

RecordingStorage can be used to create an FS usable for session recording.

type SyncMode

type SyncMode uint8

SyncMode is used to determine how a file is synced when closed.

const (
	// Asynchronous mode will trigger a file to sync to the storage
	// bucket on a recurring interval once it has been closed. It will continue
	// retrying until the root container is closed.
	// Asynchronous is the default sync mode.
	Asynchronous SyncMode = iota

	// Synchronous mode will cause a file closed call to block until the file
	// has been synced to the storage bucket. Any error while syncing the file
	// will be returned to the caller of Close.
	Synchronous

	// NoSync mode will result in Close not syncing the file to the storage
	// bucket.
	NoSync
)

type TempFile

type TempFile interface {
	File
	io.Seeker
}

TempFile is a temporary File. It will get removed when Closed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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