cstorage

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CStorage added in v1.0.1

type CStorage interface {
	// CreateBucket creates the Bucket in the project.
	CreateBucket(ctx context.Context, input CreateBucketInput) error
	// PutObject set the value passed in the indicated bucket
	PutObject(ctx context.Context, input PutObjectInput) error
	// PutObjects set multiple values passed in the indicated bucket
	PutObjects(ctx context.Context, inputs ...PutObjectInput) []PutObjectOutput
	// GetObjectByKey returns the data for the object by name
	GetObjectByKey(ctx context.Context, bucket, key string) (*Object, error)
	// GetObjectUrl returns the object public url
	GetObjectUrl(bucket, key string) string
	// ListObjects return list objects by bucket, custom query using opts param (OptsListObjects)
	ListObjects(ctx context.Context, bucket string, opts ...*OptsListObjects) ([]ObjectSummary, error)
	// DeleteObject deletes the single specified object
	DeleteObject(ctx context.Context, input DeleteObjectInput) error
	// DeleteObjects deletes multiple objects specified in the input
	DeleteObjects(ctx context.Context, inputs ...DeleteObjectInput) []DeleteObjectsOutput
	// DeleteObjectsByPrefix deletes all objects from a folder (prefix)
	DeleteObjectsByPrefix(ctx context.Context, input DeletePrefixInput) error
	// DeleteObjectsByPrefixes deletes all objects from all folders (prefix) mentioned in the input
	DeleteObjectsByPrefixes(ctx context.Context, inputs ...DeletePrefixInput) []DeletePrefixOutput
	// DeleteBucket deletes the Bucket
	DeleteBucket(ctx context.Context, bucket string) error
	// DeleteBuckets deletes multiple buckets mentioned in the input
	DeleteBuckets(ctx context.Context, buckets ...string) []DeleteBucketsOutput
	// Disconnect close connect to google storage
	Disconnect() error
	// SimpleDisconnect close connect to google storage, without error
	SimpleDisconnect()
}

func NewAwsS3Storage

func NewAwsS3Storage(cfg aws.Config) CStorage

NewAwsS3Storage new instance of connection with AWS S3 storage, to close it just use Disconnect() or SimpleDisconnect()

func NewGoogleStorage

func NewGoogleStorage(ctx context.Context, opts ...option.ClientOption) (i CStorage, err error)

NewGoogleStorage new instance of connection with Google storage, to close it just use CStorage.Disconnect() or CStorage.SimpleDisconnect()

type CreateBucketInput

type CreateBucketInput struct {
	// Bucket name of the bucket to be created (required)
	Bucket string
	// ProjectId project id where the bucket will be created (required only google storage)
	ProjectId string
	// Location bucket, if empty using default region
	Location string
}

CreateBucketInput input for creating a bucket

type DeleteBucketsOutput

type DeleteBucketsOutput struct {
	// Bucket deleted bucket name
	Bucket string
	// Err an error occurred while deleting the bucket
	Err error
}

DeleteBucketsOutput output of removing multiple buckets

type DeleteObjectInput

type DeleteObjectInput struct {
	// Bucket name of the bucket where the object will be deleted (required)
	Bucket string
	// Key of the object to be deleted (required)
	Key string
}

DeleteObjectInput input for removing an object from the bucket

type DeleteObjectsOutput

type DeleteObjectsOutput struct {
	// Bucket name of the bucket where the object was deleted
	Bucket string
	// Key of the object that was deleted
	Key string
	// Err error occurred when deleting the object
	Err error
}

DeleteObjectsOutput output of removing several objects from the bucket

type DeletePrefixInput

type DeletePrefixInput struct {
	// Bucket name of the bucket where the objects will be deleted (required)
	Bucket string
	// Prefix name where the objects will be deleted (required)
	Prefix string
}

DeletePrefixInput input to remove a folder (prefix) of objects from the bucket

type DeletePrefixOutput

type DeletePrefixOutput struct {
	// Bucket name of the bucket where the objects were deleted
	Bucket string
	// Prefix that was deleted
	Prefix string
	// Err an error occurred while deleting objects from the folder
	Err error
}

DeletePrefixOutput output of removing multiple object folders from bucket

type MimeType

type MimeType string
const (
	MimeTypePdf  MimeType = "application/pdf"
	MimeTypeText MimeType = "text/plain"
	MimeTypeAvif MimeType = "image/avif"
	MimeTypeCss  MimeType = "text/css; charset=utf-8"
	MimeTypeGif  MimeType = "image/gif"
	MimeTypeHtml MimeType = "text/html; charset=utf-8"
	MimeTypeJpeg MimeType = "image/jpeg"
	MimeTypeJs   MimeType = "text/javascript; charset=utf-8"
	MimeTypeJson MimeType = "application/json"
	MimeTypePng  MimeType = "image/png"
	MimeTypeMp4  MimeType = "video/mp4"
	MimeTypeMp3  MimeType = "audio/mp3"
	MimeTypeSvg  MimeType = "image/svg+xml"
	MimeTypeWasm MimeType = "application/wasm"
	MimeTypeWebp MimeType = "image/webp"
	MimeTypeXml  MimeType = "text/xml; charset=utf-8"
)

func (MimeType) String

func (f MimeType) String() string

type Object

type Object struct {
	Key            string
	Url            string
	MimeType       MimeType
	Content        []byte
	Size           int64
	VersionId      string
	LastModifiedAt time.Time
}

func (Object) ParseContent

func (o Object) ParseContent(dest any) error

type ObjectPage

type ObjectPage struct {
}

type ObjectSummary

type ObjectSummary struct {
	Key            string
	Url            string
	Size           int64
	LastModifiedAt time.Time
}

type OptsListObjects

type OptsListObjects struct {
	// Delimiter returns results in a directory-like fashion.
	// Results will contain only objects whose names, aside from the
	// prefix, do not contain delimiter. Objects whose names,
	// aside from the prefix, contain delimiter will have their name,
	// truncated after the delimiter, returned in prefixes.
	// Duplicate prefixes are omitted.
	// Must be set to / when used with the MatchGlob parameter to filter results
	// in a directory-like mode.
	// Optional.
	Delimiter string
	// Prefix is the prefix filter to query objects
	// whose names begin with this prefix.
	// Optional.
	Prefix string
}

OptsListObjects bucket object search options

func MergeOptsListObjectsByParams added in v1.0.7

func MergeOptsListObjectsByParams(opts []*OptsListObjects) *OptsListObjects

MergeOptsListObjectsByParams assembles the OptsListObjects object from optional parameters.

func NewOptsListObjects

func NewOptsListObjects() *OptsListObjects

NewOptsListObjects creates a new OptsListObjects instance

func (*OptsListObjects) SetDelimiter

func (o *OptsListObjects) SetDelimiter(s string) *OptsListObjects

SetDelimiter sets value for the Delimiter field

func (*OptsListObjects) SetPrefix

func (o *OptsListObjects) SetPrefix(s string) *OptsListObjects

SetPrefix sets value for the Prefix field

type PutObjectInput

type PutObjectInput struct {
	// Bucket name of the bucket where the object will be created (required)
	Bucket string
	// Key of the object that will be created (required)
	Key string
	// MimeType type of content of the object that will be created (required)
	MimeType MimeType
	// Content of the object that will be created (required)
	Content any
}

PutObjectInput input for creating/updating an object in the bucket

type PutObjectOutput

type PutObjectOutput struct {
	// Bucket name of the bucket where the object will be created
	Bucket string
	// Key of the object that will be created
	Key string
	// Err error occurred when putting the object
	Err error
}

PutObjectOutput output for creating/updating multiple objects in the bucket

Jump to

Keyboard shortcuts

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