Documentation
¶
Overview ¶
Package remote 提供多种远程存储方式的统一接口。
Index ¶
- Constants
- type COSClient
- func (c *COSClient) Close() error
- func (c *COSClient) Delete(ctx context.Context, remotePath string) error
- func (c *COSClient) Download(ctx context.Context, remotePath string) ([]byte, error)
- func (c *COSClient) List(ctx context.Context, options ListOptions) (ListResult, error)
- func (c *COSClient) Upload(ctx context.Context, remotePath string, data []byte) error
- type COSConfig
- type Client
- type Error
- type FTPClient
- func (c *FTPClient) Close() error
- func (c *FTPClient) Delete(ctx context.Context, remotePath string) error
- func (c *FTPClient) Download(ctx context.Context, remotePath string) ([]byte, error)
- func (c *FTPClient) List(ctx context.Context, options ListOptions) (ListResult, error)
- func (c *FTPClient) Upload(ctx context.Context, remotePath string, data []byte) error
- type FTPConfig
- type FileInfo
- type ListOptions
- type ListResult
- type OSSClient
- func (c *OSSClient) Close() error
- func (c *OSSClient) Delete(ctx context.Context, remotePath string) error
- func (c *OSSClient) Download(ctx context.Context, remotePath string) ([]byte, error)
- func (c *OSSClient) List(ctx context.Context, options ListOptions) (ListResult, error)
- func (c *OSSClient) Upload(ctx context.Context, remotePath string, data []byte) error
- type OSSConfig
- type SFTPClient
- func (c *SFTPClient) Close() error
- func (c *SFTPClient) Delete(ctx context.Context, remotePath string) error
- func (c *SFTPClient) Download(ctx context.Context, remotePath string) ([]byte, error)
- func (c *SFTPClient) List(ctx context.Context, options ListOptions) (ListResult, error)
- func (c *SFTPClient) Upload(ctx context.Context, remotePath string, data []byte) error
- type SFTPConfig
Constants ¶
const ( TypeFTP = "ftp" // FTP存储类型 TypeSFTP = "sftp" // SFTP存储类型 TypeCOS = "cos" // 腾讯云COS存储类型 TypeOSS = "oss" // 阿里云OSS存储类型 )
存储类型常量定义
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type COSClient ¶
type COSClient struct {
// contains filtered or unexported fields
}
COSClient 实现了腾讯云COS存储的客户端。 注意:COSClient是并发安全的,因为底层COS SDK客户端本身是并发安全的。
func NewCOSClient ¶
NewCOSClient 创建一个新的COS客户端。
func (*COSClient) List ¶
func (c *COSClient) List(ctx context.Context, options ListOptions) (ListResult, error)
List 实现了Client接口的List方法。
type Client ¶
type Client interface {
Upload(ctx context.Context, remotePath string, data []byte) error
Download(ctx context.Context, remotePath string) ([]byte, error)
Delete(ctx context.Context, remotePath string) error
List(ctx context.Context, options ListOptions) (ListResult, error)
Close() error
}
Client 定义了远程存储的统一接口。 注意:所有方法都应是并发安全的。
type FTPClient ¶
type FTPClient struct {
// contains filtered or unexported fields
}
FTPClient 实现了FTP存储的客户端。 注意:FTPClient是并发安全的。
func (*FTPClient) List ¶
func (c *FTPClient) List(ctx context.Context, options ListOptions) (ListResult, error)
List 实现了Client接口的List方法。 注意:FTP 的 Prefix 表示待列出内容的目录路径,非对象前缀。 列出前会检测/恢复连接,返回结果按文件名排序后做本地分页。
type FileInfo ¶
type FileInfo struct {
Name string // 文件名
Size int64 // 文件大小(字节)
ModTime time.Time // 修改时间
IsDir bool // 是否为目录
}
FileInfo 定义了文件的元数据信息
type ListOptions ¶
type ListOptions struct {
Prefix string // 文件名前缀过滤或目录路径,可选
Marker string // 分页标记,可选
MaxKeys int // 每次返回的最大文件数量,可选
}
ListOptions 定义了分页和过滤选项 注意:不同存储类型对 Prefix 的语义不同:
- COS/OSS:对象键前缀过滤
- FTP/SFTP:待列出内容的目录路径
type ListResult ¶
type ListResult struct {
Files []FileInfo // 文件信息列表
NextMarker string // 下一个分页标记
IsTruncated bool // 是否还有更多数据
}
ListResult 定义了List方法的返回结果
type OSSClient ¶
type OSSClient struct {
// contains filtered or unexported fields
}
OSSClient 实现了阿里云OSS存储的客户端。 注意:OSSClient是并发安全的,因为底层OSS SDK客户端本身是并发安全的。
func NewOSSClient ¶
NewOSSClient 创建一个新的OSS客户端。
func (*OSSClient) List ¶
func (c *OSSClient) List(ctx context.Context, options ListOptions) (ListResult, error)
List 实现了Client接口的List方法。
type SFTPClient ¶
type SFTPClient struct {
// contains filtered or unexported fields
}
SFTPClient 实现了SFTP存储的客户端。 注意:SFTPClient是并发安全的。
func NewSFTPClient ¶
func NewSFTPClient(config SFTPConfig, args ...ssh.HostKeyCallback) (*SFTPClient, error)
NewSFTPClient 创建一个新的SFTP客户端。 - config SFTP 连接配置 - args 可选的主机密钥回调,未提供时使用 ssh.InsecureIgnoreHostKey 返回值:
- 创建成功返回 *SFTPClient
- 地址格式错误、认证信息缺失或连接失败时返回错误
func (*SFTPClient) Close ¶
func (c *SFTPClient) Close() error
Close 实现了Client接口的Close方法。 关闭 SFTP 客户端和底层 SSH 连接,并将内部引用置空,标记客户端为已关闭状态。
func (*SFTPClient) Delete ¶
func (c *SFTPClient) Delete(ctx context.Context, remotePath string) error
Delete 实现了Client接口的Delete方法。 删除前会检测/恢复连接。
func (*SFTPClient) List ¶
func (c *SFTPClient) List(ctx context.Context, options ListOptions) (ListResult, error)
List 实现了Client接口的List方法。 注意:SFTP 的 Prefix 表示待列出内容的目录路径,非对象前缀。 列出前会检测/恢复连接,返回结果按文件名排序后做本地分页。