filesystem

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 22 Imported by: 0

README

File System

Open in Gitpod

tests Go Report Card PkgGoDev

Usage

storage, err = filesystem.NewStorage(filesystem.Disk{
  DiskName:             "S3",
  Driver:               filesystem.DRIVER_S3,
  Url:                  config.MediaUrl,
  Region:               config.MediaRegion,
  Key:                  config.MediaKey,
  Secret:               config.MediaSecret,
  Bucket:               config.MediaBucket,
  UsePathStyleEndpoint: true,
})

if err != nil {
  return err.Error()
}

Documentation

Index

Constants

View Source
const CDN = "cdn"
View Source
const DEFAULT = "default"
View Source
const DRIVER_S3 = "s3"
View Source
const DRIVER_SQL = "sql"
View Source
const DRIVER_STATIC = "static"
View Source
const PATH_SEPARATOR = "/"
View Source
const ROOT_PATH = PATH_SEPARATOR

Variables

This section is empty.

Functions

This section is empty.

Types

type Disk

type Disk struct {
	DiskName   string
	Driver     string
	Url        string
	Visibility string // public, private (not implemented)

	// SQL options
	DB        *sql.DB // for sql
	TableName string  // for sql

	// Local options
	Root string // for local filesystem (not implemented)

	// S3 options
	Key      string // for s3
	Secret   string // for s3
	Region   string // for s3
	Bucket   string // for s3
	Endpoint string // for s3

	// Allows you to enable the client to use path-style addressing, i.e.,
	// https://s3.amazonaws.com/BUCKET/KEY . By default, the S3 client will use virtual
	// hosted bucket addressing when possible( https://BUCKET.s3.amazonaws.com/KEY ).
	UsePathStyleEndpoint bool // for s3

	Throw bool // for s3 (not implemented)
}

type S3Storage

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

S3Storage implements the StorageInterface for an S3 compliant file storage, i.e. AWS S3, DigitalOcean Spaces, Minio, etc

func (*S3Storage) Copy

func (s *S3Storage) Copy(originFile, targetFile string) error

func (*S3Storage) DeleteDirectory

func (s *S3Storage) DeleteDirectory(directory string) error

DeleteDirectory deletes a directory

func (*S3Storage) DeleteFile

func (s *S3Storage) DeleteFile(filePaths []string) error

func (*S3Storage) Directories

func (s *S3Storage) Directories(dir string) ([]string, error)

Directories lists the sub-directories in the specified directory

func (*S3Storage) Exists

func (s *S3Storage) Exists(file string) (bool, error)

func (*S3Storage) Files

func (s *S3Storage) Files(dir string) ([]string, error)

Files lists the files in the specified directory

func (*S3Storage) LastModified

func (s *S3Storage) LastModified(file string) (time.Time, error)

func (*S3Storage) MakeDirectory

func (s *S3Storage) MakeDirectory(directory string) error

func (*S3Storage) Missing

func (s *S3Storage) Missing(file string) (bool, error)

func (*S3Storage) Move

func (s *S3Storage) Move(oldFile, newFile string) error

func (*S3Storage) Put

func (s *S3Storage) Put(filePath string, content []byte) error

func (*S3Storage) PutFile

func (s *S3Storage) PutFile(filePath string, source filesystem.File) (string, error)

func (*S3Storage) PutFileAs

func (s *S3Storage) PutFileAs(filePath string, source filesystem.File, name string) (string, error)

func (*S3Storage) ReadFile added in v0.2.0

func (s *S3Storage) ReadFile(file string) ([]byte, error)

func (*S3Storage) Size

func (s *S3Storage) Size(file string) (int64, error)

func (*S3Storage) Url

func (s *S3Storage) Url(file string) (string, error)

type SQLStorage added in v0.1.0

type SQLStorage struct {
	DB                 *sql.DB
	FilestoreTable     string
	URL                string
	AutomigrateEnabled bool
	DebugEnabled       bool
	// contains filtered or unexported fields
}

func NewSqlStorage added in v0.1.0

func NewSqlStorage(options SqlStorageOptions) (*SQLStorage, error)

func (*SQLStorage) Copy added in v0.1.0

func (s *SQLStorage) Copy(originFilePath, targetFilePath string) error

func (*SQLStorage) DeleteDirectory added in v0.1.0

func (s *SQLStorage) DeleteDirectory(directoryPath string) error

DeleteDirectory deletes a directory

func (*SQLStorage) DeleteFile added in v0.1.0

func (s *SQLStorage) DeleteFile(filePaths []string) error

func (*SQLStorage) Directories added in v0.1.0

func (s *SQLStorage) Directories(directoryPath string) ([]string, error)

Directories lists the sub-directories in the specified directory

func (*SQLStorage) Exists added in v0.1.0

func (s *SQLStorage) Exists(path string) (bool, error)

func (*SQLStorage) Files added in v0.1.0

func (s *SQLStorage) Files(directoryPath string) ([]string, error)

Files lists the files in the specified directory

func (*SQLStorage) LastModified added in v0.1.0

func (s *SQLStorage) LastModified(filePath string) (time.Time, error)

func (*SQLStorage) MakeDirectory added in v0.1.0

func (s *SQLStorage) MakeDirectory(directoryPath string) error

func (*SQLStorage) Move added in v0.1.0

func (s *SQLStorage) Move(originFilePath, targetFilePath string) error

func (*SQLStorage) Put added in v0.1.0

func (s *SQLStorage) Put(filePath string, content []byte) error

func (*SQLStorage) PutFile added in v0.1.0

func (s *SQLStorage) PutFile(filePath string, source string) (string, error)

func (*SQLStorage) ReadFile added in v0.1.0

func (s *SQLStorage) ReadFile(filePath string) ([]byte, error)

func (*SQLStorage) Size added in v0.1.0

func (s *SQLStorage) Size(filePath string) (int64, error)

func (*SQLStorage) Url added in v0.1.0

func (s *SQLStorage) Url(filePath string) (string, error)

type SqlStorageOptions added in v0.1.0

type SqlStorageOptions struct {
	DB                 *sql.DB
	FilestoreTable     string
	URL                string
	AutomigrateEnabled bool
	DebugEnabled       bool
}

type StaticStorage

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

StaticStorage implements StorageInterface it represents a static (read only) storage, i.e. CDN the only supported method is Url(filepath)

func (*StaticStorage) Copy

func (s *StaticStorage) Copy(originFile, targetFile string) error

func (*StaticStorage) DeleteDirectory

func (s *StaticStorage) DeleteDirectory(dirPath string) error

func (*StaticStorage) DeleteFile

func (s *StaticStorage) DeleteFile(filePaths []string) error

func (*StaticStorage) Directories

func (s *StaticStorage) Directories(dirPath string) ([]string, error)

func (*StaticStorage) Exists added in v0.2.0

func (s *StaticStorage) Exists(filePath string) (bool, error)

func (*StaticStorage) Files

func (s *StaticStorage) Files(dirPath string) ([]string, error)

func (*StaticStorage) LastModified

func (s *StaticStorage) LastModified(filePath string) (time.Time, error)

func (*StaticStorage) MakeDirectory

func (s *StaticStorage) MakeDirectory(dirPath string) error

func (*StaticStorage) Move

func (s *StaticStorage) Move(originFile, targetFile string) error

func (*StaticStorage) Put

func (s *StaticStorage) Put(filePath string, content []byte) error

func (*StaticStorage) ReadFile added in v0.2.0

func (s *StaticStorage) ReadFile(filePath string) ([]byte, error)

func (*StaticStorage) Size

func (s *StaticStorage) Size(filePath string) (int64, error)

func (*StaticStorage) Url

func (s *StaticStorage) Url(filePath string) (string, error)

type StorageInterface

type StorageInterface interface {
	Copy(originFile, targetFile string) error
	DeleteDirectory(dirPath string) error
	DeleteFile(filePaths []string) error
	Directories(dir string) ([]string, error)
	Exists(filePath string) (bool, error)
	Files(dir string) ([]string, error)
	MakeDirectory(dir string) error
	Move(originFile, targetFile string) error
	Put(filePath string, content []byte) error
	ReadFile(filePath string) ([]byte, error)
	Size(filePath string) (int64, error)
	LastModified(file string) (time.Time, error)
	Url(file string) (string, error)
}

func NewStorage

func NewStorage(disk Disk) (StorageInterface, error)

Jump to

Keyboard shortcuts

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