Documentation
¶
Overview ¶
Package file 提供文件处理、上传和水印功能
Index ¶
- Variables
- func InitFileSystem()
- func IsAllowedImageExt(ext string) bool
- func ProcessFilesInParallel(files []string, processor func(string) error, maxConcurrency int64) error
- func ProcessLargeFile(filePath string, processor ChunkProcessor) error
- func RefreshAllFileCache()
- func RefreshFileCache(fullPath string) error
- func SetCacheExpiration(duration time.Duration)
- type ChunkProcessor
- type File
- func (f *File) ChunkRead(chunkSize int64, handler func([]byte) error) error
- func (f *File) Ext() string
- func (f *File) FullPath() string
- func (f *File) ModifyTime() (time.Time, error)
- func (f *File) Name() string
- func (f *File) Path() string
- func (f *File) ReadAll() ([]byte, error)
- func (f *File) ReadBlock(size int64) ([]byte, int64, error)
- func (f *File) ReadLine() (string, error)
- func (f *File) Size() (int64, error)
- func (f *File) StreamRead(handler func([]byte) error) error
- func (f *File) Truncate() error
- func (f *File) Write(b []byte) error
- func (f *File) WriteAppend(b []byte) error
- func (f *File) WriteAt(b []byte, offset int64) (int, error)
- type FileError
- type FileHandler
- type FileInfoCache
- type Filer
- type UploadConfig
- type UploadResult
- type Watermark
- type WatermarkConfig
- type WatermarkPos
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidPath = errors.New("无效的文件路径") ErrFileNotExist = errors.New("文件不存在") ErrReadFailed = errors.New("读取文件失败") ErrWriteFailed = errors.New("写入文件失败") )
View Source
var FileCache = struct { sync.RWMutex m map[string]*FileInfoCache }{/* contains filtered or unexported fields */}
FileCache 全局文件信息缓存
Functions ¶
func ProcessFilesInParallel ¶
func ProcessFilesInParallel(files []string, processor func(string) error, maxConcurrency int64) error
ProcessFilesInParallel 并行处理多个文件,带并发限制
func ProcessLargeFile ¶
func ProcessLargeFile(filePath string, processor ChunkProcessor) error
ProcessLargeFile 处理大文件
func SetCacheExpiration ¶
SetCacheExpiration 设置缓存过期时间
Types ¶
type ChunkProcessor ¶
ChunkProcessor 用于处理大文件的分块处理器
type File ¶
type File struct {
// contains filtered or unexported fields
}
File 文件类
func (*File) StreamRead ¶
StreamRead 流式读取文件
type FileHandler ¶
type FileHandler struct {
// contains filtered or unexported fields
}
FileHandler 处理文件上传和水印
func NewFileHandler ¶
func NewFileHandler(cfg UploadConfig) (*FileHandler, error)
NewFileHandler 创建一个新的 FileHandler 实例
func (*FileHandler) Upload ¶
func (fh *FileHandler) Upload(field string, r *http.Request) ([]UploadResult, error)
Upload 执行上传操作
type FileInfoCache ¶
type FileInfoCache struct {
// contains filtered or unexported fields
}
FileInfoCache 用于缓存文件信息
type Filer ¶
type Filer interface {
Size() (int64, error)
ReadAll() ([]byte, error)
ReadLine() (string, error)
ReadBlock(size int64) ([]byte, int64, error)
Write(b []byte) error
WriteAt(b []byte, offset int64) (int, error)
WriteAppend(b []byte) error
Truncate() error
Ext() string
Name() string
Path() string
FullPath() string
ModifyTime() (time.Time, error)
StreamRead(handler func([]byte) error) error
ChunkRead(chunkSize int64, handler func([]byte) error) error
}
Filer 文件接口
type UploadConfig ¶
type UploadConfig struct {
Dir string
Format string
MaxSize int64
AllowedExt []string
Watermark *WatermarkConfig
}
UploadConfig 上传配置
type UploadResult ¶
UploadResult 表示单个文件的上传结果
type Watermark ¶
type Watermark struct {
// contains filtered or unexported fields
}
Watermark 用于给图片添加水印功能
func NewWatermark ¶
func NewWatermark(cfg *WatermarkConfig) (*Watermark, error)
NewWatermark 创建一个新的 Watermark 实例
type WatermarkConfig ¶
type WatermarkConfig struct {
Path string
Padding int
Pos WatermarkPos
Transparency uint8
Rotation float64
}
WatermarkConfig 水印配置
type WatermarkPos ¶
type WatermarkPos int
WatermarkPos 表示水印的位置
const ( TopLeft WatermarkPos = iota TopRight BottomLeft BottomRight Center )
水印的位置常量
Click to show internal directories.
Click to hide internal directories.