storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ErrCodeNotFound = "NotFound"
View Source
const TypeS3 = "s3"

Variables

This section is empty.

Functions

This section is empty.

Types

type S3Config

type S3Config struct {
	AccessKeyID          string        `json:"access_key_id" yaml:"access_key_id"`
	SecretAccessKey      string        `json:"secret_access_key" yaml:"secret_access_key"`
	Bucket               string        `json:"bucket" yaml:"bucket"`
	Region               string        `json:"region" yaml:"region"`
	Directory            string        `json:"directory" yaml:"directory"`
	PresignURLExpiration time.Duration `json:"presign_url_expiration" yaml:"presign_url_expiration"`
	MaxKeys              int64         `json:"max_keys" yaml:"max_keys"`

	// Set nil to use default value
	Endpoint         *string `json:"endpoint" yaml:"endpoint"`
	S3ForcePathStyle *bool   `json:"s3_force_path_style" yaml:"s3_force_path_style"`
	DisableSSL       *bool   `json:"disable_ssl" yaml:"disable_ssl"`
}

S3Config defines config for s3 storage

type S3Storage

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

S3Storage defines methods to access S3

func (*S3Storage) DeleteFile

func (s *S3Storage) DeleteFile(ctx context.Context, objectKey string) error

DeleteFile deletes file from S3

func (*S3Storage) DownloadFile

func (s *S3Storage) DownloadFile(ctx context.Context, objectKey string) (io.ReadCloser, error)

DownloadFile downloads file from S3 returns the body

func (*S3Storage) Exist

func (s *S3Storage) Exist(ctx context.Context, objectKey string) (bool, error)

Exist checks if file is existed

func (*S3Storage) GetURL

func (s *S3Storage) GetURL(ctx context.Context, objectKey string) (string, error)

GetURL returns the url of a file

func (*S3Storage) UploadFile

func (s *S3Storage) UploadFile(ctx context.Context, objectKey string, reader io.Reader) (string, error)

UploadFile reads from reader and uploads to S3

type Storage

type Storage interface {
	UploadFile(ctx context.Context, objectKey string, reader io.Reader) (string, error)
	DownloadFile(ctx context.Context, objectKey string) (io.ReadCloser, error)
	DeleteFile(ctx context.Context, objectKey string) error
	GetURL(ctx context.Context, objectKey string) (string, error)
	Exist(ctx context.Context, objectKey string) (bool, error)
}

Storage defines interface for store data file

func NewStorage

func NewStorage(ctx context.Context, storageType string, config interface{}) (Storage, error)

NewStorage creates a instance of FileStore with provided config

Jump to

Keyboard shortcuts

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