filesystem

package module
v0.0.0-...-31ccecd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2025 License: MIT Imports: 11 Imported by: 0

README

GO Filesystem

Under development...

License

MIT © 2024 yu1ec

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsQiniu

func AsQiniu(fs Filesystem) (*qiniu.QiniuFilesystem, bool)

AsQiniu 将通用文件系统转换为七牛云文件系统 如果不是七牛云文件系统,第二个返回值为 false

func BuildUploadKey

func BuildUploadKey(uploadDir, fileExt string) string

BuildUploadKey 生成上传文件的key

func MustAsQiniu

func MustAsQiniu(fs Filesystem) *qiniu.QiniuFilesystem

Types

type Filesystem

type Filesystem interface {
	Put(ctx context.Context, path string, data []byte) error // 将数据写入文件
	PutWithoutContext(path string, data []byte) error        // 将数据写入文件不带上下文
	Get(path string) ([]byte, error)                         // 获取文件内容
	GetUrl(path string) string                               // 获取文件的URL

	// GetSignedUrl 获取签名URL
	// path: 文件路径
	// expires: 过期时间 单位/秒
	GetSignedUrl(path string, expires int64) (string, error)
	GetImageWidthHeight(path string) (int, int, error) // 获取图片的宽高

	MustGetSignedUrl(path string, expires int64) string // 获取签名URL

	Delete(path string) error // 删除文件
	Exists(path string) bool  // 判断文件是否存在
}

Filesystem 文件系统接口

func NewStorage

func NewStorage(driver config.FilesystemDriver) Filesystem

NewStorage 创建文件系统

func NewStorageWithError

func NewStorageWithError(driver config.FilesystemDriver) (Filesystem, error)

NewStorageWithError 带错误信息的文件系统创建

Directories

Path Synopsis
driver

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL