Documentation
¶
Overview ¶
Package storage 提供对象存储集成(对标 Spring Cloud 的 OSS/对象存储抽象, 兼容 S3 协议的 MinIO/阿里云 OSS/腾讯云 COS 等):常用操作封装 + 原生客户端暴露。
Index ¶
- type Client
- func (c *Client) Client() *minio.Client
- func (c *Client) Delete(ctx context.Context, bucket, objectName string) error
- func (c *Client) EnsureBucket(ctx context.Context, bucket string) error
- func (c *Client) Get(ctx context.Context, bucket, objectName string) (io.ReadCloser, *ObjectInfo, error)
- func (c *Client) GetBytes(ctx context.Context, bucket, objectName string) ([]byte, error)
- func (c *Client) List(ctx context.Context, bucket, prefix string, limit int) ([]ObjectInfo, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) PresignedGet(ctx context.Context, bucket, objectName string, ttl time.Duration) (string, error)
- func (c *Client) PresignedPut(ctx context.Context, bucket, objectName string, ttl time.Duration) (string, error)
- func (c *Client) Put(ctx context.Context, bucket, objectName string, reader io.Reader, size int64, ...) error
- func (c *Client) PutBytes(ctx context.Context, bucket, objectName string, data []byte, ...) error
- func (c *Client) Stat(ctx context.Context, bucket, objectName string) (*ObjectInfo, error)
- type Config
- type ObjectInfo
- type StorageTemplate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 是对象存储模板实现。
func (*Client) EnsureBucket ¶
EnsureBucket 确保桶存在。
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, bucket, objectName string) (io.ReadCloser, *ObjectInfo, error)
Get 下载对象。
func (*Client) PresignedGet ¶
func (c *Client) PresignedGet(ctx context.Context, bucket, objectName string, ttl time.Duration) (string, error)
PresignedGet 预签名下载 URL。
func (*Client) PresignedPut ¶
func (c *Client) PresignedPut(ctx context.Context, bucket, objectName string, ttl time.Duration) (string, error)
PresignedPut 预签名上传 URL。
func (*Client) Put ¶
func (c *Client) Put(ctx context.Context, bucket, objectName string, reader io.Reader, size int64, contentType string) error
Put 上传对象。
type Config ¶
type Config struct {
// Endpoint 服务地址(如 127.0.0.1:9000 或 oss-cn-hangzhou.aliyuncs.com)。
Endpoint string
// AccessKey/SecretKey 访问密钥。
AccessKey string
SecretKey string
// UseSSL 是否启用 HTTPS。
UseSSL bool
// Region 区域(OSS 必需,如 oss-cn-hangzhou)。
Region string
// Bucket 默认桶(可空,操作时显式指定)。
Bucket string
}
Config 对象存储配置(兼容 S3 协议:MinIO/OSS/COS 等)。
type ObjectInfo ¶
type ObjectInfo struct {
Key string `json:"key"`
Size int64 `json:"size"`
ContentType string `json:"content_type"`
LastModified time.Time `json:"last_modified"`
ETag string `json:"etag"`
}
ObjectInfo 对象信息。
type StorageTemplate ¶
type StorageTemplate interface {
// Ping 连通性检查(列举默认桶或根)。
Ping(ctx context.Context) error
// EnsureBucket 确保桶存在(不存在则创建)。
EnsureBucket(ctx context.Context, bucket string) error
// Put 上传对象(reader 流式上传)。
Put(ctx context.Context, bucket, objectName string, reader io.Reader, size int64, contentType string) error
// PutBytes 上传字节数据。
PutBytes(ctx context.Context, bucket, objectName string, data []byte, contentType string) error
// Get 下载对象(返回读取流,调用方负责 Close)。
Get(ctx context.Context, bucket, objectName string) (io.ReadCloser, *ObjectInfo, error)
// GetBytes 下载对象为字节(小文件场景)。
GetBytes(ctx context.Context, bucket, objectName string) ([]byte, error)
// Delete 删除对象(不存在不报错)。
Delete(ctx context.Context, bucket, objectName string) error
// Stat 对象信息(不存在返回错误)。
Stat(ctx context.Context, bucket, objectName string) (*ObjectInfo, error)
// List 列举前缀下的对象(最多 limit 个,limit<=0 时全部)。
List(ctx context.Context, bucket, prefix string, limit int) ([]ObjectInfo, error)
// PresignedPut 生成预签名上传 URL(临时直传,防暴露密钥)。
PresignedPut(ctx context.Context, bucket, objectName string, ttl time.Duration) (string, error)
// PresignedGet 生成预签名下载 URL。
PresignedGet(ctx context.Context, bucket, objectName string, ttl time.Duration) (string, error)
// Client 返回原生 MinIO 客户端(高级操作入口)。
Client() *minio.Client
}
StorageTemplate 高频操作层:上传/下载/删除/列举/签名 + 原生客户端。
Click to show internal directories.
Click to hide internal directories.