Documentation ¶
Index ¶
- func DeleteHandlerFunc(storage Storage, repository FileRepository) http.HandlerFunc
- func DownloadHandlerFunc(storage Storage, cache Cache, resizer image.Resizer, repository FileRepository) http.HandlerFunc
- func UploadHandlerFunc(storage Storage, repository FileRepository) http.HandlerFunc
- type Cache
- type DiskCache
- type File
- type FileRepository
- type MongoFileRepository
- func (repo MongoFileRepository) Create(ctx context.Context, file File) (File, error)
- func (repo MongoFileRepository) Delete(ctx context.Context, id interface{}) error
- func (repo MongoFileRepository) FindAllByIDs(ctx context.Context, ids interface{}) ([]File, error)
- func (repo MongoFileRepository) FindByID(ctx context.Context, id interface{}) (File, error)
- type Slug
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteHandlerFunc ¶
func DeleteHandlerFunc(storage Storage, repository FileRepository) http.HandlerFunc
DeleteHandlerFunc handles deletion request
func DownloadHandlerFunc ¶
func DownloadHandlerFunc(storage Storage, cache Cache, resizer image.Resizer, repository FileRepository) http.HandlerFunc
DownloadHandlerFunc handles downloading request
func UploadHandlerFunc ¶
func UploadHandlerFunc(storage Storage, repository FileRepository) http.HandlerFunc
UpdateHandlerFunc handles uploading request
Types ¶
type Cache ¶
type Cache interface { Exists(path string) bool Retrieve(path string) (io.ReadCloser, error) Store(body io.Reader, path string) error }
Cache uses to storing or retrieving files from hidden or inaccessible place
type DiskCache ¶
type DiskCache struct {
// contains filtered or unexported fields
}
DiskCache implements Cache interface with local disk storage
func NewDiskCache ¶
NewDiskCache returns a new DiskCache instance
func (*DiskCache) Close ¶
func (c *DiskCache) Close()
Close closes the doneCh which will breaking an infinite-loop file deletion function
type File ¶
type File struct { // Identifier of the file ID primitive.ObjectID `bson:"_id" json:"id" graphql:"-"` // An uploaded file path Path string `bson:"path" json:"path" graphql:"path"` // An original file name FileName string `bson:"fileName" json:"fileName" graphql:"fileName"` // Valid URL string composes with file name and ID Slug string `bson:"slug" json:"slug" graphql:"slug"` // An optional field #1 for using in some storage server OptionalField1 string `bson:"optionalField1" json:"optionalField1,omitempty" graphql:"optionalField1"` // An optional field #2 for using in some storage server OptionalField2 string `bson:"optionalField2" json:"optionalField2,omitempty" graphql:"optionalField2"` // An optional field #3 for using in some storage server OptionalField3 string `bson:"optionalField3" json:"optionalField3,omitempty" graphql:"optionalField3"` // Date-time that the file was created CreatedAt time.Time `bson:"createdAt" json:"createdAt" graphql:"createdAt"` // Date-time that the file was updated UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt" graphql:"updatedAt"` }
File is an uploaded object on the storage server
func (File) MarshalJSON ¶
MarshalJSON is a custom JSON marshaling function of file entity
type FileRepository ¶
type FileRepository interface { Create(ctx context.Context, file File) (File, error) Delete(ctx context.Context, id interface{}) error FindAllByIDs(ctx context.Context, ids interface{}) ([]File, error) FindByID(ctx context.Context, id interface{}) (File, error) }
A fileRepository interface
func NewFileRepository ¶
func NewFileRepository(db mongo.Database) FileRepository
NewFileRepository returns a MongoFileRepository instance
type MongoFileRepository ¶
type MongoFileRepository struct {
// contains filtered or unexported fields
}
MongoFileRepository implements fileRepository on MongoDB
func (MongoFileRepository) Delete ¶
func (repo MongoFileRepository) Delete(ctx context.Context, id interface{}) error
Delete performs deletion a file record by its ID
func (MongoFileRepository) FindAllByIDs ¶
func (repo MongoFileRepository) FindAllByIDs(ctx context.Context, ids interface{}) ([]File, error)
FindAllByIDs returns list of files from list of IDs