Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrFmDatabaseClientError = errors.New("file manager database client error") // TODO: should be renamed or adapted ErrFmDBClientQueryFailed = errors.New("file manager database client query failed") // TODO: should be renamed or adapted ErrFmFileNotFound = errors.New("file manager file not found") ErrFmNewFileLocationMissing = errors.New("file manager file location missing") ErrFmNoInputFile = errors.New("file manager no input file") )
var (
// DBFilesTableName -> can be changed as needed...
DBFilesTableName = "fm_files"
)
Functions ¶
func GetFilesDBTableName ¶
func GetFilesDBTableName() string
Types ¶
type DriverFileInterface ¶
type DriverFileInterface interface { Save() Copy() Move() Delete() Create() Touch() List() }
type File ¶
type File struct { // InstanceName, partitioning can be setup! FMInstance string `gorm:"primaryKey;size:50;not null;<-:create"` ID UUID `gorm:"primaryKey;not null;<-:create"` // File Name Name string `gorm:"size:256"` // FullName contains the Name+Extension FullName string `gorm:"size:256"` // It's the FullName of the file but containing the original name of it! OriginalName string `gorm:"size:256;<-:create"` // File Description Description string `gorm:"size:256"` // Size Bytes Size int64 `gorm:"<-:create"` // CategoryID -> also an optional field CategoryID *uuid.UUID // Extension -> xls, doc etc... Extension string `gorm:"size:30;<-:create"` // ContentType -> application/json, application/text, etc... ContentType string `gorm:"size:50;<-:create"` // these are the locations where the file is stored // there can be multiple ones, having as a backup option or for read performance... //Locations Locations Locations FileLocationsMeta FileCreatedAt *time.Time `gorm:"null;index:idx_core_dates;<-:create"` FileUpdatedAt *time.Time `gorm:"null;index:idx_core_dates"` CreatedAt *time.Time `gorm:"null;index:idx_core_dates;<-:create"` UpdatedAt *time.Time `gorm:"null;index:idx_core_dates"` DeletedAt *time.Time `gorm:"null;index:idx_core_dates"` CreatedByID *uuid.UUID `gorm:"null;<-:create"` UpdatedByID *uuid.UUID `gorm:"null"` DeletedByID *uuid.UUID `gorm:"null"` // contains filtered or unexported fields }
func (*File) Copy ¶
func (f *File) Copy()
Copy -> copies the current file from current location to another location (destination)
func (*File) Delete ¶
func (f *File) Delete()
Delete - deletes the current file from all available locations
func (*File) Move ¶
func (f *File) Move()
Move - moves the current file's location to another location (destination)
func (*File) Read ¶
func (f *File) Read()
Read - reads the file contents from the default location, if not available, it will seek for other locations and try fetching the contents. If none of locations are responding, an error will be returned
func (*File) SaveAs ¶
func (f *File) SaveAs()
SaveAs - creates a clone of current file having a new ID
func (*File) TableName ¶
TableName -> Get the Database table name from the file manager https://gorm.io/docs/conventions.html -> NOTE TableName doesn’t allow dynamic name, its result will be cached for future, to use dynamic name, you can use Scopes, for example:
type FileLocationMeta ¶
type FileLocationMeta struct { // this is the instance Name LocationName string FileInfo gofileDriver.FileInfo }
type FileLocationsMeta ¶
type FileLocationsMeta []FileLocationMeta
func (FileLocationsMeta) GormDBDataType ¶
GormDBDataType gorm db data type This is the Database data type which is sent to the DB
func (FileLocationsMeta) GormDataType ¶
func (FileLocationsMeta) GormDataType() string
func (*FileLocationsMeta) Scan ¶
func (l *FileLocationsMeta) Scan(value interface{}) error
Scan -> this is the func which is called when it's necessary to read from the Database to the defined variable with this type
type FileManager ¶
type FileManager struct { // The DB Client DBClient *gorm.DB DBAutoMigrate bool // Name -> the name should be short max 50 chars Name string Locations Locations LocationsIndexed map[string]Location // contains filtered or unexported fields }
FileManager - metadata will be stored
func GetInstance ¶
func GetInstance(fm ...*FileManager) *FileManager
GetInstance -> it should be called once somewhere in the app?! It checks for table structure
func (*FileManager) DatabaseAutoMigrate ¶
func (fm *FileManager) DatabaseAutoMigrate()
DatabaseAutoMigrate - create all necessary tables, alter,add columns
func (*FileManager) FindFile ¶
func (fm *FileManager) FindFile(o FindFileOptions) (*File, error)
FindFile -> it will search for the described file in the database if nothing is found, an error will be returned
func (*FileManager) FindFiles ¶
func (fm *FileManager) FindFiles(o FindFilesOptions) *File
FindFiles -> TODO:
func (*FileManager) GetError ¶
func (fm *FileManager) GetError() error
func (*FileManager) GetInternalError ¶
func (fm *FileManager) GetInternalError() error
func (*FileManager) NewFile ¶
func (fm *FileManager) NewFile() *NewFile
NewFile -> create a new file in the DB
type FindFileOptions ¶
type FindFilesOptions ¶
type Location ¶
type Location struct { // this is used driver name //DriverType string // Name -> the name is the identity Name string // the driver is the one that creates the bridge between the client and the destination server (location) // this is the instance with which the will interact Driver driver.LocationInterface `gorm:"-"` // contains filtered or unexported fields }
type Locations ¶
type Locations []Location
type Locations []Location
func (Locations) GormDBDataType ¶
GormDBDataType gorm db data type This is the Database data type which is sent to the DB
func (Locations) GormDataType ¶
type NewFile ¶
type NewFile struct { // InputFile -> should be indicated, other params are optional! InputFilePath string GraphQLFile *graphql.Upload //======= Optional ======= \\ // Name -> can Name string Description string CategoryID *uuid.UUID // Extension -> is needed only when a physical file is not provided, but a Bytes input has been provided Extension string // ========= Locations ==========\\ //Locations Locations Locations []NewFileLocation // contains filtered or unexported fields }
type NewFileLocation ¶
type NewFileLocation struct { // this is the instance name LocationName string // if none of the lower params are indicated, it will take the current files basedir and it will // recreate on the destination location //========= Optional Params ===========\\ // DirPath -> is optional, a new folder path is indicated, the file name remains the same! DirPath string // FilePath -> is optional, a new full file path is indicated (it includes as the dir path) FilePath string }