Documentation
¶
Index ¶
- Variables
- func GetFilesDBTableName() string
- type DriverFileInterface
- type File
- func (f *File) Copy()
- func (f *File) Delete()
- func (f *File) Get() gofileDriver.FileInterface
- func (f *File) GetFromLoc(locName string) (gofileDriver.FileInterface, bool)
- func (f *File) GetTmpFilePath() (string, error)
- func (f *File) Move()
- func (f *File) Read() ([]byte, error)
- func (f *File) Save() (*File, error)
- func (f *File) SaveAs()
- func (f *File) SetDefaultFile(file gofileDriver.FileInterface)
- func (f *File) SetFileManager(fm *FileManager)
- func (f *File) SetFilesIndexed(files map[LocationName]gofileDriver.FileInterface)
- func (f *File) SetLocationsIndexed(locations map[LocationName]FileLocationMeta)
- func (f *File) TableName() string
- type FileLocationMeta
- type FileLocationsMeta
- type FileManager
- func (fm *FileManager) DB() *gorm.DB
- func (fm *FileManager) DatabaseAutoMigrate()
- func (fm *FileManager) FindFile(fileModel interface{}, cb func(db *gorm.DB) *gorm.DB) error
- func (fm *FileManager) GetError() error
- func (fm *FileManager) GetInternalError() error
- func (fm *FileManager) NewFile() *NewFile
- type Location
- type LocationName
- type Locations
- type NewFile
- type NewFileLocation
- type UUID
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") ErrFileModelShouldBePointerOfAStruct = errors.New("file manager file model should be pointer of a struct") )
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) Get ¶
func (f *File) Get() gofileDriver.FileInterface
func (*File) GetFromLoc ¶
func (f *File) GetFromLoc(locName string) (gofileDriver.FileInterface, bool)
ReadFromLoc -> sa citeasca din anumita locatie...
func (*File) GetTmpFilePath ¶
GetTmpFilePath -> it will return a tmp file path which after it will be auto destroyed
func (*File) Move ¶
func (f *File) Move()
Move - moves the current file's location to another location (destination)
func (*File) SaveAs ¶
func (f *File) SaveAs()
SaveAs - creates a clone of current file having a new ID
func (*File) SetDefaultFile ¶
func (f *File) SetDefaultFile(file gofileDriver.FileInterface)
func (*File) SetFileManager ¶
func (f *File) SetFileManager(fm *FileManager)
func (*File) SetFilesIndexed ¶
func (f *File) SetFilesIndexed(files map[LocationName]gofileDriver.FileInterface)
func (*File) SetLocationsIndexed ¶
func (f *File) SetLocationsIndexed(locations map[LocationName]FileLocationMeta)
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) DB ¶
func (fm *FileManager) DB() *gorm.DB
func (*FileManager) DatabaseAutoMigrate ¶
func (fm *FileManager) DatabaseAutoMigrate()
DatabaseAutoMigrate - create all necessary tables, alter,add columns
func (*FileManager) FindFile ¶
FindFile -> it will search for the described file in the database if nothing is found, an error will be returned
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 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 LocationName ¶
type LocationName string
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 // FileModel - asta e modelul din partea la client... FileModel interface{} // ========= 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 }