Documentation
¶
Index ¶
- func IsImage(ext string) bool
- func IsVideo(ext string) bool
- func NewAliyun(c *Config) oss.StorageInterface
- func NewAzure(c *Config) oss.StorageInterface
- func NewMinio(c *Config) oss.StorageInterface
- func NewS3(c *Config) oss.StorageInterface
- func NewStorage(c *Config) (oss.StorageInterface, error)
- func NewTencentCloud(c *Config) oss.StorageInterface
- func RestoreOriginalFileName(uniqueName string, withExt ...bool) string
- type Config
- type FileConfig
- type FileHeader
- type FileSystem
- type FileType
- type ImageConfig
- type LocalFileSystem
- func (fs *LocalFileSystem) Delete(p string) error
- func (fs *LocalFileSystem) Get(p string) (*os.File, error)
- func (fs *LocalFileSystem) GetEndpoint() string
- func (fs *LocalFileSystem) GetFullPath(p string) string
- func (fs *LocalFileSystem) GetStream(p string) (io.ReadCloser, error)
- func (fs *LocalFileSystem) GetURL(p string) (string, error)
- func (fs *LocalFileSystem) List(p string) ([]*oss.Object, error)
- func (fs *LocalFileSystem) Put(p string, r io.Reader) (*oss.Object, error)
- type ThumbnailConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTencentCloud ¶
func NewTencentCloud(c *Config) oss.StorageInterface
NewTencentCloud new tencent cloud cos
func RestoreOriginalFileName ¶
RestoreOriginalFileName restores the original file name by removing the unique suffix. If withExt is true, it preserves the file extension.
Types ¶
type Config ¶
type Config struct {
Provider string
ID string
Secret string
Region string
Bucket string
Endpoint string
}
Config config
type FileConfig ¶
type FileConfig struct {
Path string `json:"path"`
MaxSize int64 `json:"max_size"`
AllowType []FileType `json:"allow_type"`
}
FileConfig file config
type FileHeader ¶
type FileHeader struct {
Name string `json:"name"`
Size int `json:"size"`
Path string `json:"path"`
Type string `json:"type"`
Ext string `json:"ext"`
Raw *multipart.FileHeader `json:"raw"`
Metadata any `json:"metadata,omitempty"`
}
FileHeader file header
func GetFileHeader ¶
func GetFileHeader(f *multipart.FileHeader, prefix ...string) *FileHeader
GetFileHeader gets file header data and handles file renaming to ensure uniqueness
type FileSystem ¶
type FileSystem interface {
GetFullPath(p string) string
Get(p string) (*os.File, error)
GetStream(p string) (io.ReadCloser, error)
Put(p string, r io.Reader) (*oss.Object, error)
Delete(p string) error
List(p string) ([]*oss.Object, error)
GetEndpoint() string
GetURL(p string) (string, error)
}
FileSystem represents the interface for file system storage.
type ImageConfig ¶
type ImageConfig struct {
Path string `json:"path"`
MaxSize int64 `json:"max_size"`
Thumbnail ThumbnailConfig `json:"thumbnail"`
}
ImageConfig image config
type LocalFileSystem ¶
type LocalFileSystem struct {
Folder string
}
LocalFileSystem implements the FileSystem interface for local file system storage.
func NewFileSystem ¶
func NewFileSystem(folder string) *LocalFileSystem
NewFileSystem creates a new local file system storage. It ensures the folder exists; if not, it creates the folder.
func (*LocalFileSystem) Delete ¶
func (fs *LocalFileSystem) Delete(p string) error
Delete deletes a file.
func (*LocalFileSystem) Get ¶
func (fs *LocalFileSystem) Get(p string) (*os.File, error)
Get receives a file with the given path.
func (*LocalFileSystem) GetEndpoint ¶
func (fs *LocalFileSystem) GetEndpoint() string
GetEndpoint gets the endpoint. For FileSystem, the endpoint is "/".
func (*LocalFileSystem) GetFullPath ¶
func (fs *LocalFileSystem) GetFullPath(p string) string
GetFullPath returns the full path from absolute / relative path.
func (*LocalFileSystem) GetStream ¶
func (fs *LocalFileSystem) GetStream(p string) (io.ReadCloser, error)
GetStream gets a file as a stream.
func (*LocalFileSystem) GetURL ¶
func (fs *LocalFileSystem) GetURL(p string) (string, error)
GetURL gets the public accessible URL.
type ThumbnailConfig ¶
type ThumbnailConfig struct {
Path string `json:"path"`
MaxWidth int64 `json:"max_width"`
MaxHeight int64 `json:"max_height"`
}
ThumbnailConfig thumbnail config