harestorage

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 9 Imported by: 0

README

harestorage Go Reference

A simple, unified Go interface for object storage

Installation

go get github.com/taknb2nch/harestorage

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GCSStorage

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

GCSStorage implements the Storage interface for Google Cloud Storage (GCS).

func NewGCSStorage

func NewGCSStorage(client *storage.Client, bucketName string) *GCSStorage

NewGCSStorage creates a new GCSStorage instance with the specified client, bucket name.

func (*GCSStorage) Copy

func (s *GCSStorage) Copy(ctx context.Context, src string, dst string) error

Copy copies an object from the source path to the destination path.

func (*GCSStorage) Delete

func (s *GCSStorage) Delete(ctx context.Context, name string) error

Delete deletes the object with the specified name.

func (*GCSStorage) DeleteAll

func (s *GCSStorage) DeleteAll(ctx context.Context, prefix string) error

DeleteAll deletes all objects matching the specified prefix.

func (*GCSStorage) Get

func (s *GCSStorage) Get(ctx context.Context, name string) (io.ReadCloser, error)

Get returns an io.ReadCloser to read the object with the specified name.

func (*GCSStorage) List

func (s *GCSStorage) List(ctx context.Context, prefix string) ([]*ObjectInfo, error)

List returns a list of objects matching the specified prefix.

func (*GCSStorage) Move

func (s *GCSStorage) Move(ctx context.Context, src string, dst string) error

Move moves (renames) an object from the source path to the destination path.

func (*GCSStorage) Name

func (s *GCSStorage) Name() string

Name returns the bucketName (identifier) of this storage.

func (*GCSStorage) PathJoin

func (s *GCSStorage) PathJoin(elem ...string) string

PathJoin joins multiple path elements according to the storage's format.

func (*GCSStorage) Put

func (s *GCSStorage) Put(ctx context.Context, name string, r io.Reader, opts *PutOptions) (int64, error)

Put saves data to the storage with the specified name.

type LocalStorage

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

LocalStorage implements the Storage interface for the local filesystem.

func NewLocalStorage

func NewLocalStorage(rootDir string, name string) *LocalStorage

NewLocalStorage creates a new LocalStorage instance with the specified root directory and name.

func (*LocalStorage) Copy

func (s *LocalStorage) Copy(ctx context.Context, src string, dst string) error

Copy copies an object from the source path to the destination path.

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(ctx context.Context, name string) error

Delete deletes the object with the specified name.

func (*LocalStorage) DeleteAll

func (s *LocalStorage) DeleteAll(ctx context.Context, prefix string) error

DeleteAll deletes all objects matching the specified prefix.

func (*LocalStorage) Get

func (s *LocalStorage) Get(ctx context.Context, name string) (io.ReadCloser, error)

Get returns an io.ReadCloser to read the object with the specified name.

func (*LocalStorage) List

func (s *LocalStorage) List(ctx context.Context, prefix string) ([]*ObjectInfo, error)

List returns a list of objects matching the specified prefix.

func (*LocalStorage) Move

func (s *LocalStorage) Move(ctx context.Context, src string, dst string) error

Move moves (renames) an object from the source path to the destination path.

func (*LocalStorage) Name

func (s *LocalStorage) Name() string

Name returns the name (identifier) of this storage.

func (*LocalStorage) PathJoin

func (s *LocalStorage) PathJoin(elem ...string) string

PathJoin joins multiple path elements according to the storage's format.

func (*LocalStorage) Put

func (s *LocalStorage) Put(ctx context.Context, name string, r io.Reader, opts *PutOptions) (int64, error)

Put saves data to the storage with the specified name.

type ObjectInfo

type ObjectInfo struct {
	// Name is the full path (name) of the object.
	Name string
	// Size is the data size of the object in bytes.
	Size int64
	// UpdatedAt is the time when the object was last updated.
	UpdatedAt time.Time
	// Metadata is the metadata associated with the object.
	Metadata map[string]string
}

ObjectInfo holds detailed information about an object in the storage.

type PutOptions

type PutOptions struct {
	// ContentType specifies the MIME type of the object.
	ContentType string
	// Metadata is arbitrary metadata associated with the object.
	Metadata map[string]string
}

PutOptions holds optional settings for saving an object.

type Storage

type Storage interface {
	// Name returns the name (identifier) of this storage.
	Name() string
	// Get returns an io.ReadCloser to read the object with the specified name.
	Get(ctx context.Context, name string) (io.ReadCloser, error)
	// Put saves data to the storage with the specified name.
	Put(ctx context.Context, name string, r io.Reader, opts *PutOptions) (int64, error)
	// List returns a list of objects matching the specified prefix.
	List(ctx context.Context, prefix string) ([]*ObjectInfo, error)
	// Copy copies an object from the source path to the destination path.
	Copy(ctx context.Context, src string, dst string) error
	// Move moves (renames) an object from the source path to the destination path.
	Move(ctx context.Context, src string, dst string) error
	// Delete deletes the object with the specified name.
	Delete(ctx context.Context, name string) error
	// DeleteAll deletes all objects matching the specified prefix.
	DeleteAll(ctx context.Context, prefix string) error
	// PathJoin joins multiple path elements according to the storage's format.
	PathJoin(elem ...string) string
}

Storage defines the interface for a set of operations on object storage.

Jump to

Keyboard shortcuts

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