file

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package file provides various functionalities for reading, writing and manipulating files and supports different file storage backends like aws, azure, gcp, sftp, ftp along with the support for local files.

Index

Constants

View Source
const (
	Local = "LOCAL"
	Azure = "AZURE"
	AWS   = "AWS"
	GCP   = "GCP"
	SFTP  = "SFTP"
	FTP   = "FTP"
)
View Source
const (
	READ      = Mode("r")
	WRITE     = Mode("w")
	READWRITE = Mode("rw")
	APPEND    = Mode("a")
)
View Source
const ErrListingNotSupported = errors.Error(`Listing not supported for provided file store.` +
	` Please set a valid value of FILE_STORE:{LOCAL or SFTP}`)

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSConfig

type AWSConfig struct {
	AccessKey string
	SecretKey string
	Token     string
	Bucket    string
	Region    string
}

type AzureConfig

type AzureConfig struct {
	AccountName   string
	AccessKey     string
	ContainerName string
	BlockSize     string
	Parallelism   string
}

AzureConfig is used to store configurations related to Azure cloud storage.

type Config

type Config struct {
	FileStore string
	Azure     AzureConfig
	AWS       AWSConfig
	GCP       GCPConfig
	SFTP      SFTPConfig
	FTP       FTPConfig
}

Config is redefined in this package similar to what defined in gofr package.

type FTPConfig

type FTPConfig struct {
	Host          string
	User          string
	Password      string
	Port          int
	RetryDuration time.Duration
}

FTPConfig is used to store configuration related to FTP.

type File

type File interface {
	// Open should open the file in the provided mode. Implementation depends on the file storage to be used.
	Open() error
	// Read calls the internal file descriptor method to Read.
	Read([]byte) (int, error)
	// Write calls the internal file descriptor method to Write.
	Write([]byte) (int, error)
	// Seek calls the internal file descriptor method to Seek
	Seek(offset int64, whence int) (int64, error)
	// Close calls the internal file descriptor method to Close.
	Close() error
}

type GCPConfig

type GCPConfig struct {
	GCPKey     string
	BucketName string
}

GCPConfig is used to store configurations related to GCP cloud storage.

type Mode

type Mode string

type S3Client

type S3Client interface {
	GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
	PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
}

S3Client is an interface for interacting with AWS S3.

type SFTPConfig

type SFTPConfig struct {
	Host     string
	User     string
	Password string
	Port     int
}

SFTPConfig is used to store configuration related to SFTP.

type Storage

type Storage interface {
	File
	// List lists all the files in the directory
	List(directory string) ([]string, error)
	// Move moves the file from source to destination
	Move(src, dest string) error
	// Copy copies the file from source to destination
	Copy(src, dest string) (int, error)
	// Delete deletes the given file
	Delete(fileName string) error
}

func New

func New(config *Config, filename string, mode Mode) (Storage, error)

New takes file specific config struct and calls respective constructor functions for opening files

func NewWithConfig

func NewWithConfig(config gofr.Config, filename string, mode Mode) (Storage, error)

NewWithConfig takes the gofr config and creates Config struct specific to this file package and then calls New()

Jump to

Keyboard shortcuts

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