Documentation
¶
Index ¶
Constants ¶
View Source
const Lens scene.ModuleName = "storage"
Variables ¶
View Source
var ( ErrStorageFailed = _eg.CreateError(1, "storage failed") ErrFileNotFound = _eg.CreateError(2, "file not found") ErrStorageNotFound = _eg.CreateError(3, "storage not found") ErrFailToLoad = _eg.CreateError(4, "fail to load") ErrFailToStore = _eg.CreateError(5, "fail to store") ErrFailToDelete = _eg.CreateError(6, "fail to delete") ErrLoadingMeta = _eg.CreateError(7, "loading meta") ErrInvalidFileID = _eg.CreateError(8, "invalid file id") ErrStorageError = _eg.CreateError(9, "storage error") ErrInvalidOffset = _eg.CreateError(10, "invalid offset") ErrInvalidLength = _eg.CreateError(11, "invalid length") ErrUnknownError = _eg.CreateError(12, "unknown error") ErrInitPartUploadFailed = _eg.CreateError(13, "init part upload failed") ErrUploadSessionNotFound = _eg.CreateError(14, "upload session not found") ErrStorePartFailed = _eg.CreateError(15, "store part upload failed") ErrFailToAbortMultipartStore = _eg.CreateError(16, "fail to abort") ErrMetaNotFound = _eg.CreateError(17, "meta not found") ErrFailToListMeta = _eg.CreateError(18, "fail to list meta") ErrFileIDExists = _eg.CreateError(19, "file id exists") )
View Source
var ( PermFileNaming = permission.Create("storage:file:naming") PermFileUpload = permission.Create("storage:file:upload") PermFileDelete = permission.Create("storage:file:delete") PermFileDownload = permission.Create("storage:file:download") PermFileList = permission.Create("storage:file:list") )
Functions ¶
func NewIoInterface ¶
func NewIoInterface(srv IStorageService, fileId FileID) (IoInterface, FileMeta, error)
Types ¶
type FileID ¶
type FileID string
FileID is the unique identifier of a file in storage. it is composed with {Provider}://{ID} example: tos.buketName://objectName example: local.name://objectName
func NewFileIDWithUUID ¶ added in v0.3.2
func ParseFileID ¶
type FileMeta ¶
type FileMeta struct {
FileID FileID `gorm:"primaryKey;column:file_id" json:"file_id"`
Provider string `gorm:"column:provider" json:"provider"`
Identifier string `gorm:"column:identifier" json:"identifier"`
OriginalFilename string `json:"original_filename" gorm:"column:original_filename"`
ContentType string `json:"content_type" gorm:"column:content_type"`
ContentLength int64 `json:"content_length" gorm:"column:content_length"`
Md5Checksum string `json:"md5_checksum" gorm:"column:md5_checksum"`
Finished bool `json:"finished" gorm:"column:finished"`
CreatedAt time.Time `json:"created_at" gorm:"column:created_at"`
UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at"`
}
func (*FileMeta) FillMissing ¶
type IFileMetaRepository ¶
type IFileMetaRepository interface {
scene.Named
// Store will store the metadata in the repository
// will overwrite the old metadata if exists
Store(meta FileMeta) error
Load(fileId FileID) (meta FileMeta, err error)
Delete(fileId FileID) error
List(provider string, offset, limit int64) (model.PaginationResult[FileMeta], error)
}
type IStorageProvider ¶
type IStorageProvider interface {
scene.Named
// ProviderName return provider name in fileId
ProviderName() string
// HealthCheck will check if this Storage provider is accessible
HealthCheck() error
// Meta will return any possible metadata can be found, as a fallback option if IFileMetaRepository failed
Meta(fileId FileID) (meta FileMeta, err error)
Load(fileId FileID, offset, length int64) (reader io.ReadCloser, err error)
LoadAll(fileId FileID) (reader io.ReadCloser, err error)
// Store will store the data in the storage at path and return the fileId,
// if path not exists, it will create the path.
Store(fileId FileID, data io.Reader) (err error)
Delete(fileId FileID) error
// Multipart related
InitMultipartStore(fileId FileID) (uploadId string, err error)
StorePart(uploadId string, partNumber int, data io.Reader) error
CompleteMultipartStore(uploadId string) error
AbortMultipartStore(uploadId string) error
// GetPublicURL get public url which can be access in public network
GetPublicURL(fileId FileID) (url string, err error)
}
type IStorageService ¶
type IStorageService interface {
scene.Service
ListProviders() []string
// ListMeta will list meta from specific provider.
ListMeta(provider string, offset, limit int64) (model.PaginationResult[FileMeta], error)
// Meta return the meta given a fileId
Meta(fileId FileID) (meta FileMeta, err error)
// Load will load file data at offset with length.
// basically io.Seeker & io.Reader
Load(fileId FileID, offset, length int64) (data []byte, err error)
// LoadAll will load data, if reach end of file it will return io.EOF
// only use when you know the size of the data
LoadAll(fileId FileID) (data []byte, err error)
Delete(fileId FileID) error
// Store will store data at default provider
// it calls StoreAt internally
Store(data []byte, meta FileMeta) (fileId FileID, err error)
// StoreAt will store data using the given provider and identifier.
// If provider is empty, the service default provider will be used.
// If identifier is empty, the service will generate one internally.
StoreAt(provider, identifier string, data []byte, meta FileMeta) (fileId FileID, err error)
// Multipart related
// InitMultipartStore will initialize a multipart upload using the given provider and identifier.
// If provider is empty, the service default provider will be used.
// If identifier is empty, the service will generate one internally.
// It returns both the resolved file id and the upload id.
InitMultipartStore(provider, identifier string, meta FileMeta) (fileId FileID, uploadId string, err error)
StorePart(uploadId string, partNumber int, data []byte) error
StorePartReader(uploadId string, partNumber int, data io.Reader) error
CompleteMultipartStore(uploadId string) error
AbortMultiPartStore(uploadId string) error
// GetPublicURL get public url which can be access in public network
GetPublicURL(fileId FileID) (url string, err error)
}
type IUploadSessionTracker ¶
type IUploadSessionTracker interface {
scene.Named
Save(uploadId string, session UploadSession) error
Get(uploadId string) (UploadSession, error)
Delete(uploadId string) error
}
type UploadSession ¶
UploadSession contains info to resume/complete uploads
Click to show internal directories.
Click to hide internal directories.