package storage import ( "context" "io" "time" ) // ObjectStorage 对象存储抽象。MinIO / 阿里云 OSS(S3 兼容) / 腾讯云 COS 等共用此接口, // 业务层只依赖 Put/Delete/URL,迁移云厂商时只改配置与驱动初始化。 type ObjectStorage interface { // Put 上传对象,返回公网可访问 URL Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) (publicURL string, err error) // Delete 删除对象(可选清理) Delete(ctx context.Context, key string) error // PublicBase 浏览器访问前缀(用于校验消息中的图片 URL) PublicBase() string // EnsureBucket 开发环境自动建桶 EnsureBucket(ctx context.Context) error } // PutResult 上传结果 type PutResult struct { Key string URL string ContentType string Size int64 } // NewObjectKey 生成带日期前缀的对象键,避免冲突 func NewObjectKey(prefix, ext string) string { now := time.Now() return prefix + "/" + now.Format("2006/01/02") + "/" + now.Format("150405") + "-" + randomHex(8) + ext }