storage

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResourceNotFound      = errors.New("resource not found")
	ErrResourceInvalidFormat = errors.New("invalid resource format")
	ErrEmptyResource         = errors.New("resource has no content")
	ErrResourceAlreadyExists = errors.New("resource already exists")
	ErrSourceFolderNotFound  = errors.New("source folder not found")
	ErrSourceFolderEmpty     = errors.New("source folder is empty")
	ErrSourceFile            = errors.New("source is a file, should be a folder")
	ErrFileNil               = errors.New("no file provided")
)

Functions

func ReadFile

func ReadFile(ctx context.Context, resource Resource, path string, fn ReadFileFunc) ([]byte, error)

ReadFile reads the content of the file located in path from the given resource. The integration the specific storage providers is provided by the ReadFileFunc.

func UploadDir

func UploadDir(ctx context.Context, resource Resource, src string, fn WalkDirFunc) error

UploadDir uploads the directory and all the sub elements found in src using the provided WalkDirFunc for each file found inside src. They will be uploaded as the assets for the given Resource.

func UploadZip

func UploadZip(ctx context.Context, resource Resource, file *os.File, fn WalkDirFunc) error

UploadZip uploads the given file to where the given resource is stored.

func WalkDir

func WalkDir(ctx context.Context, src string, walkFunc WalkDirFunc) error

WalkDir finds all the files and directories inside src and executes walkFunc on every file.

Types

type ReadFileFunc

type ReadFileFunc func(ctx context.Context, resource Resource, path string) (io.ReadCloser, error)

ReadFileFunc is used to provide integration with cloud providers while using the same business logic when reading the content of a file.

type Resource

type Resource interface {
	// GetUUID returns the UUID v4 that identifies the current Resource.
	GetUUID() string
	// GetOwner returns who is the owner of the current Resource.
	GetOwner() string
	// GetVersion returns the numeric version of the current Resource. Resources increment their version as new
	// updates are introduced to them.
	GetVersion() uint64
}

Resource represents the resource that a user wants to download from a cloud storage.

func NewResource

func NewResource(uuid string, owner string, version uint64) Resource

NewResource initializes a new Resource with the given values.

type Storage

type Storage interface {
	// GetFile returns the content of file from a given path.
	GetFile(ctx context.Context, resource Resource, path string) ([]byte, error)
	// Download returns a URL to download a resource from.
	Download(ctx context.Context, resource Resource) (string, error)
	// UploadDir uploads assets located in the given source folder and placed them into the given resource.
	UploadDir(ctx context.Context, resource Resource, source string) error
	// UploadZip uploads a compressed set of assets of the given resource.
	//
	//	Resources can have a compressed representation of the resource itself that acts like a cache, it contains all the
	//	files from the said resource. This function uploads that zip file.
	UploadZip(ctx context.Context, resource Resource, file *os.File) error
}

Storage holds the methods to interact with a Cloud provider storage.

func NewGCS

func NewGCS(client *storage.Client, bucket string, pk []byte, accessID string) Storage

NewGCS initializes a new implementation of Storage using the Google Cloud Storage service.

func NewS3v1

func NewS3v1(client *s3api.S3, uploader *s3manager.Uploader, bucket string) Storage

NewS3v1 initializes a new implementation of Storage using the AWS S3 v1 service.

func NewS3v2

func NewS3v2(client *s3api.Client, bucket string) Storage

NewS3v2 initializes a new implementation of Storage using the AWS S3 service.

type WalkDirFunc

type WalkDirFunc func(ctx context.Context, path string, body io.Reader) error

WalkDirFunc defines the signature of a WalkDirFunc that will be executed on every file when walking through a directory.

Jump to

Keyboard shortcuts

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