Documentation
¶
Overview ¶
Package s3kit provides a small, idiomatic client for S3-compatible object storage built on top of AWS SDK for Go v2.
Index ¶
- Variables
- func TransferSnowballAutoExtract(ctx context.Context, source *Client, destination *Client, ...) error
- type ArchiveExtractMode
- type ArchiveExtractedObject
- type ArchiveFormat
- type ArchiveTransferOptions
- type ArchiveTransferResult
- type Client
- func (c *Client) BucketExists(ctx context.Context, name string) (bool, error)
- func (c *Client) CopyObject(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string) error
- func (c *Client) CopyObjectVersion(ctx context.Context, srcBucket string, srcKey string, srcVersionID string, ...) (string, error)
- func (c *Client) CopyObjectVersionByNumber(ctx context.Context, srcBucket string, srcKey string, versionNumber int, ...) (string, error)
- func (c *Client) CreateBucket(ctx context.Context, name string) error
- func (c *Client) DeleteAllObjectVersions(ctx context.Context, bucket, key string) error
- func (c *Client) DeleteBucket(ctx context.Context, name string) error
- func (c *Client) DeleteObject(ctx context.Context, bucket, key string) error
- func (c *Client) DeleteObjectVersion(ctx context.Context, bucket, key, versionID string) error
- func (c *Client) DeleteObjectVersionByNumber(ctx context.Context, bucket string, key string, versionNumber int) error
- func (c *Client) DeleteObjectVersions(ctx context.Context, bucket string, versions []ObjectVersionIdentifier) error
- func (c *Client) DeleteObjectVersionsByNumber(ctx context.Context, bucket string, versions []ObjectVersionNumberIdentifier) error
- func (c *Client) DeleteObjects(ctx context.Context, bucket string, keys []string) error
- func (c *Client) DownloadFile(ctx context.Context, bucket, key, localPath string) error
- func (c *Client) DownloadFileVersion(ctx context.Context, bucket, key, localPath, versionID string) error
- func (c *Client) DownloadFileVersionByNumber(ctx context.Context, bucket string, key string, localPath string, ...) error
- func (c *Client) EmptyBucket(ctx context.Context, bucket string) error
- func (c *Client) EmptyBucketVersions(ctx context.Context, bucket string) error
- func (c *Client) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
- func (c *Client) GetObjectBytes(ctx context.Context, bucket, key string) ([]byte, error)
- func (c *Client) GetObjectVersion(ctx context.Context, bucket, key, versionID string) (io.ReadCloser, error)
- func (c *Client) GetObjectVersionByNumber(ctx context.Context, bucket string, key string, versionNumber int) (io.ReadCloser, error)
- func (c *Client) GetObjectVersionBytes(ctx context.Context, bucket, key, versionID string) ([]byte, error)
- func (c *Client) GetObjectVersionBytesByNumber(ctx context.Context, bucket string, key string, versionNumber int) ([]byte, error)
- func (c *Client) ListBuckets(ctx context.Context) ([]string, error)
- func (c *Client) ListObjectVersions(ctx context.Context, bucket, key string) ([]ObjectVersion, error)
- func (c *Client) ListObjects(ctx context.Context, bucket, prefix string) ([]string, error)
- func (c *Client) MoveObject(ctx context.Context, bucket, srcKey, dstKey string) error
- func (c *Client) MoveObjectVersion(ctx context.Context, bucket string, srcKey string, srcVersionID string, ...) (string, error)
- func (c *Client) MoveObjectVersionByNumber(ctx context.Context, bucket string, srcKey string, versionNumber int, ...) (string, error)
- func (c *Client) ObjectExists(ctx context.Context, bucket, key string) (bool, error)
- func (c *Client) ObjectVersionExists(ctx context.Context, bucket, key, versionID string) (bool, error)
- func (c *Client) ObjectVersionExistsByNumber(ctx context.Context, bucket string, key string, versionNumber int) (bool, error)
- func (c *Client) ObjectVersionID(ctx context.Context, bucket, key string, versionNumber int) (string, error)
- func (c *Client) PresignGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
- func (c *Client) PresignGetObjectVersion(ctx context.Context, bucket string, key string, versionID string, ...) (string, error)
- func (c *Client) PresignGetObjectVersionByNumber(ctx context.Context, bucket string, key string, versionNumber int, ...) (string, error)
- func (c *Client) PresignPutObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
- func (c *Client) PutObject(ctx context.Context, bucket, key string, body io.Reader, contentType string) error
- func (c *Client) PutObjectBytes(ctx context.Context, bucket, key string, data []byte, contentType string) error
- func (c *Client) PutObjectBytesSnowballAutoExtract(ctx context.Context, bucket string, key string, data []byte, ...) error
- func (c *Client) PutObjectBytesVersion(ctx context.Context, bucket string, key string, data []byte, ...) (string, error)
- func (c *Client) PutObjectSnowballAutoExtract(ctx context.Context, bucket string, key string, body io.Reader, ...) error
- func (c *Client) PutObjectVersion(ctx context.Context, bucket string, key string, body io.Reader, ...) (string, error)
- func (c *Client) UploadFile(ctx context.Context, bucket, key, localPath string) error
- func (c *Client) UploadFileSnowballAutoExtract(ctx context.Context, bucket, key, localPath string) error
- func (c *Client) UploadFileVersion(ctx context.Context, bucket, key, localPath string) (string, error)
- func (c *Client) WaitBucketExists(ctx context.Context, name string, timeout time.Duration) error
- type Config
- type ObjectVersion
- type ObjectVersionIdentifier
- type ObjectVersionNumberIdentifier
- type SnowballAutoExtractTransferOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidArchiveEntryName = errors.New("s3kit: invalid archive entry name") ErrArchiveEntryLimit = errors.New("s3kit: archive entry limit exceeded") ErrArchiveSizeLimit = errors.New("s3kit: archive uncompressed size limit exceeded") ErrUnsupportedArchive = errors.New("s3kit: unsupported archive format") )
var ( // ErrInvalidVersionNumber 表示传入的对象版本号不是正整数。 ErrInvalidVersionNumber = errors.New("s3kit: version number must be greater than zero") // ErrObjectVersionNotFound 表示请求的对象历史版本不存在。 ErrObjectVersionNotFound = errors.New("s3kit: object version not found") )
Functions ¶
func TransferSnowballAutoExtract ¶ added in v0.0.4
func TransferSnowballAutoExtract( ctx context.Context, source *Client, destination *Client, opts SnowballAutoExtractTransferOptions, ) error
TransferSnowballAutoExtract streams a remote archive from source to destination and asks the destination MinIO server to extract it.
The source can be any S3-compatible endpoint that supports GetObject. The destination must be MinIO with Snowball Auto-Extract enabled, otherwise the archive is stored as a normal object with user metadata.
Types ¶
type ArchiveExtractMode ¶ added in v0.0.4
type ArchiveExtractMode string
const ( // ArchiveExtractPortable extracts the archive in the application and uploads // each file as a normal object. It works with AWS S3, MinIO, RustFS, and // generic S3-compatible targets. ArchiveExtractPortable ArchiveExtractMode = "portable" // ArchiveExtractMinIOSnowball uploads the archive with MinIO's // x-amz-meta-snowball-auto-extract metadata. It is faster for MinIO bulk // imports but is not portable to AWS S3 or RustFS. ArchiveExtractMinIOSnowball ArchiveExtractMode = "minio-snowball" )
type ArchiveExtractedObject ¶ added in v0.0.4
type ArchiveFormat ¶ added in v0.0.4
type ArchiveFormat string
const ( ArchiveFormatAuto ArchiveFormat = "" ArchiveFormatZip ArchiveFormat = "zip" ArchiveFormatTar ArchiveFormat = "tar" ArchiveFormatTarGz ArchiveFormat = "tar.gz" )
type ArchiveTransferOptions ¶ added in v0.0.4
type ArchiveTransferOptions struct {
// SourceBucket and SourceKey identify the source object when SourceURL is
// empty.
SourceBucket string
SourceKey string
// SourceURL is an optional HTTP(S) or presigned S3 URL. When set, SourceBucket
// is not required and source may be nil.
SourceURL string
// DestinationBucket receives the extracted objects. DestinationArchiveKey is
// optional in portable mode and required in MinIO Snowball mode.
DestinationBucket string
DestinationArchiveKey string
// ExtractPrefix is prepended to extracted object keys in portable mode.
ExtractPrefix string
// Mode defaults to ArchiveExtractPortable for cross-provider compatibility.
Mode ArchiveExtractMode
// Format defaults to auto-detection from SourceKey, SourceURL, or
// DestinationArchiveKey.
Format ArchiveFormat
// ContentType optionally overrides the uploaded archive content type in
// MinIO Snowball mode.
ContentType string
// TempDir optionally selects where portable mode stores the temporary archive.
TempDir string
// MaxEntries optionally limits extracted file entries in portable mode. Zero
// means unlimited.
MaxEntries int
// MaxUncompressedSize optionally limits total extracted bytes in portable
// mode. Zero means unlimited.
MaxUncompressedSize int64
}
ArchiveTransferOptions configures TransferArchiveAndExtract.
type ArchiveTransferResult ¶ added in v0.0.4
type ArchiveTransferResult struct {
Mode ArchiveExtractMode
ArchiveKey string
Extracted []ArchiveExtractedObject
ServerExtract bool
}
func TransferArchiveAndExtract ¶ added in v0.0.4
func TransferArchiveAndExtract( ctx context.Context, source *Client, destination *Client, opts ArchiveTransferOptions, ) (*ArchiveTransferResult, error)
TransferArchiveAndExtract moves an archive from S3 or HTTP(S) into a destination bucket and extracts it.
Portable mode works with AWS S3, MinIO, RustFS, and generic S3-compatible targets by extracting in the application and uploading each file. MinIO Snowball mode streams the archive to MinIO with server-side auto-extract metadata for higher bulk-import throughput.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the S3 and transfer manager clients used by the package.
func NewContext ¶ added in v0.0.2
NewContext builds a Client using the provided context while loading AWS configuration.
func (*Client) BucketExists ¶
BucketExists reports whether a bucket exists.
func (*Client) CopyObject ¶
CopyObject copies an object to a new bucket/key pair.
func (*Client) CopyObjectVersion ¶ added in v0.0.3
func (c *Client) CopyObjectVersion( ctx context.Context, srcBucket string, srcKey string, srcVersionID string, dstBucket string, dstKey string, ) (string, error)
CopyObjectVersion 按 VersionID 复制源对象历史版本,并在目标桶启用版本控制时返回新 VersionID。
func (*Client) CopyObjectVersionByNumber ¶ added in v0.0.3
func (c *Client) CopyObjectVersionByNumber( ctx context.Context, srcBucket string, srcKey string, versionNumber int, dstBucket string, dstKey string, ) (string, error)
CopyObjectVersionByNumber 按从 1 开始的版本号复制源对象历史版本。
func (*Client) CreateBucket ¶
CreateBucket creates a bucket.
func (*Client) DeleteAllObjectVersions ¶ added in v0.0.3
DeleteAllObjectVersions 永久删除单个对象 key 的所有历史版本和删除标记。
func (*Client) DeleteBucket ¶
DeleteBucket deletes a bucket.
func (*Client) DeleteObject ¶
DeleteObject deletes a single object.
func (*Client) DeleteObjectVersion ¶ added in v0.0.3
DeleteObjectVersion 按 VersionID 永久删除指定对象历史版本。
func (*Client) DeleteObjectVersionByNumber ¶ added in v0.0.3
func (c *Client) DeleteObjectVersionByNumber( ctx context.Context, bucket string, key string, versionNumber int, ) error
DeleteObjectVersionByNumber 按从 1 开始的版本号永久删除指定对象历史版本。
func (*Client) DeleteObjectVersions ¶ added in v0.0.3
func (c *Client) DeleteObjectVersions( ctx context.Context, bucket string, versions []ObjectVersionIdentifier, ) error
DeleteObjectVersions 按 VersionID 批量删除对象历史版本,并自动按 S3 1000 个对象限制分批。
func (*Client) DeleteObjectVersionsByNumber ¶ added in v0.0.3
func (c *Client) DeleteObjectVersionsByNumber( ctx context.Context, bucket string, versions []ObjectVersionNumberIdentifier, ) error
DeleteObjectVersionsByNumber 按版本号批量删除对象历史版本,并自动按 S3 1000 个对象限制分批。
func (*Client) DeleteObjects ¶
DeleteObjects deletes objects in batches that respect the S3 1000-key limit.
func (*Client) DownloadFile ¶
DownloadFile downloads an object atomically by writing to a temporary file and renaming it on success.
func (*Client) DownloadFileVersion ¶ added in v0.0.3
func (c *Client) DownloadFileVersion(ctx context.Context, bucket, key, localPath, versionID string) error
DownloadFileVersion 按 VersionID 原子下载对象历史版本,成功后再重命名临时文件。
func (*Client) DownloadFileVersionByNumber ¶ added in v0.0.3
func (c *Client) DownloadFileVersionByNumber( ctx context.Context, bucket string, key string, localPath string, versionNumber int, ) error
DownloadFileVersionByNumber 按从 1 开始的版本号原子下载对象历史版本。 版本号 1 表示最新对象版本。
func (*Client) EmptyBucket ¶
EmptyBucket deletes every object in a bucket.
func (*Client) EmptyBucketVersions ¶ added in v0.0.3
EmptyBucketVersions 永久删除版本桶里的所有对象历史版本和删除标记。
func (*Client) GetObject ¶
GetObject fetches an object body. The caller must close the returned reader.
func (*Client) GetObjectBytes ¶
GetObjectBytes fetches an object into memory.
func (*Client) GetObjectVersion ¶ added in v0.0.3
func (c *Client) GetObjectVersion(ctx context.Context, bucket, key, versionID string) (io.ReadCloser, error)
GetObjectVersion 按 VersionID 读取对象的指定历史版本。 调用方必须关闭返回的 reader。
func (*Client) GetObjectVersionByNumber ¶ added in v0.0.3
func (c *Client) GetObjectVersionByNumber( ctx context.Context, bucket string, key string, versionNumber int, ) (io.ReadCloser, error)
GetObjectVersionByNumber 按从 1 开始的版本号读取对象历史版本。 版本号 1 表示最新对象版本;调用方必须关闭返回的 reader。
func (*Client) GetObjectVersionBytes ¶ added in v0.0.3
func (c *Client) GetObjectVersionBytes(ctx context.Context, bucket, key, versionID string) ([]byte, error)
GetObjectVersionBytes 按 VersionID 将对象历史版本读取到内存。
func (*Client) GetObjectVersionBytesByNumber ¶ added in v0.0.3
func (c *Client) GetObjectVersionBytesByNumber( ctx context.Context, bucket string, key string, versionNumber int, ) ([]byte, error)
GetObjectVersionBytesByNumber 按从 1 开始的版本号将对象历史版本读取到内存。 版本号 1 表示最新对象版本。
func (*Client) ListBuckets ¶
ListBuckets lists all visible bucket names.
func (*Client) ListObjectVersions ¶ added in v0.0.3
func (c *Client) ListObjectVersions(ctx context.Context, bucket, key string) ([]ObjectVersion, error)
ListObjectVersions 列出单个对象 key 的所有可读取历史版本。
返回的 VersionNumber 从 1 开始:1 表示最新对象版本,2 表示上一个对象版本。 删除标记不可作为文件内容读取,因此不会出现在返回结果里。
func (*Client) ListObjects ¶
ListObjects lists all object keys under prefix.
func (*Client) MoveObject ¶
MoveObject copies an object and removes the source key.
func (*Client) MoveObjectVersion ¶ added in v0.0.3
func (c *Client) MoveObjectVersion( ctx context.Context, bucket string, srcKey string, srcVersionID string, dstKey string, ) (string, error)
MoveObjectVersion 按 VersionID 将源对象历史版本移动到新 key。 该方法会先复制该历史版本,再永久删除源 VersionID;目标桶启用版本控制时返回新 VersionID。
func (*Client) MoveObjectVersionByNumber ¶ added in v0.0.3
func (c *Client) MoveObjectVersionByNumber( ctx context.Context, bucket string, srcKey string, versionNumber int, dstKey string, ) (string, error)
MoveObjectVersionByNumber 按从 1 开始的版本号将源对象历史版本移动到新 key。
func (*Client) ObjectExists ¶
ObjectExists reports whether an object exists.
func (*Client) ObjectVersionExists ¶ added in v0.0.3
func (c *Client) ObjectVersionExists(ctx context.Context, bucket, key, versionID string) (bool, error)
ObjectVersionExists 判断指定 VersionID 的对象历史版本是否存在。
func (*Client) ObjectVersionExistsByNumber ¶ added in v0.0.3
func (c *Client) ObjectVersionExistsByNumber( ctx context.Context, bucket string, key string, versionNumber int, ) (bool, error)
ObjectVersionExistsByNumber 判断指定版本号的对象历史版本是否存在。
func (*Client) ObjectVersionID ¶ added in v0.0.3
func (c *Client) ObjectVersionID(ctx context.Context, bucket, key string, versionNumber int) (string, error)
ObjectVersionID 将从 1 开始的版本号解析为 S3 的 VersionID。 版本号 1 表示最新对象版本。
func (*Client) PresignGetObject ¶
func (c *Client) PresignGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
PresignGetObject creates a pre-signed GET URL.
func (*Client) PresignGetObjectVersion ¶ added in v0.0.3
func (c *Client) PresignGetObjectVersion( ctx context.Context, bucket string, key string, versionID string, expiry time.Duration, ) (string, error)
PresignGetObjectVersion 按 VersionID 创建对象历史版本的预签名 GET URL。
func (*Client) PresignGetObjectVersionByNumber ¶ added in v0.0.3
func (c *Client) PresignGetObjectVersionByNumber( ctx context.Context, bucket string, key string, versionNumber int, expiry time.Duration, ) (string, error)
PresignGetObjectVersionByNumber 按从 1 开始的版本号创建对象历史版本的预签名 GET URL。
func (*Client) PresignPutObject ¶
func (c *Client) PresignPutObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
PresignPutObject creates a pre-signed PUT URL.
func (*Client) PutObject ¶
func (c *Client) PutObject(ctx context.Context, bucket, key string, body io.Reader, contentType string) error
PutObject uploads data from body to the given bucket and key.
func (*Client) PutObjectBytes ¶
func (c *Client) PutObjectBytes(ctx context.Context, bucket, key string, data []byte, contentType string) error
PutObjectBytes uploads an in-memory byte slice.
func (*Client) PutObjectBytesSnowballAutoExtract ¶ added in v0.0.4
func (c *Client) PutObjectBytesSnowballAutoExtract( ctx context.Context, bucket string, key string, data []byte, contentType string, ) error
PutObjectBytesSnowballAutoExtract uploads an in-memory archive and asks MinIO to extract it server-side.
func (*Client) PutObjectBytesVersion ¶ added in v0.0.3
func (c *Client) PutObjectBytesVersion( ctx context.Context, bucket string, key string, data []byte, contentType string, ) (string, error)
PutObjectBytesVersion 上传内存字节切片并在桶启用版本控制时返回新对象的 VersionID。
func (*Client) PutObjectSnowballAutoExtract ¶ added in v0.0.4
func (c *Client) PutObjectSnowballAutoExtract( ctx context.Context, bucket string, key string, body io.Reader, contentType string, ) error
PutObjectSnowballAutoExtract uploads an archive and asks MinIO to extract it server-side by sending x-amz-meta-snowball-auto-extract: true.
This is a MinIO-specific extension for .tar, .tgz, and .zip bulk imports. Other S3-compatible services may store the metadata without extracting.
func (*Client) PutObjectVersion ¶ added in v0.0.3
func (c *Client) PutObjectVersion( ctx context.Context, bucket string, key string, body io.Reader, contentType string, ) (string, error)
PutObjectVersion 上传对象并在桶启用版本控制时返回新对象的 VersionID。
func (*Client) UploadFile ¶
UploadFile uploads a local file and infers its content type from the file extension.
func (*Client) UploadFileSnowballAutoExtract ¶ added in v0.0.4
func (c *Client) UploadFileSnowballAutoExtract(ctx context.Context, bucket, key, localPath string) error
UploadFileSnowballAutoExtract uploads a .tar, .tgz, or .zip archive and asks MinIO to extract it server-side by sending x-amz-meta-snowball-auto-extract: true.
This optimizes bulk imports of many small files into MinIO. It is not a portable S3 standard; non-MinIO services may store the archive as a normal object with user metadata and perform no extraction.
type Config ¶
type Config struct {
// Endpoint is the base URL of the S3-compatible service. Leave it empty to
// use the default AWS S3 endpoint resolution for the selected Region.
Endpoint string
// AccessKeyID is the static access key to use. Leave it empty to use the
// default AWS credential chain.
AccessKeyID string
// SecretAccessKey is the static secret key to use. It must be paired with
// AccessKeyID when set.
SecretAccessKey string
// SessionToken is an optional session token for temporary static
// credentials.
SessionToken string
// Region is the AWS region or S3-compatible region name. It defaults to
// us-east-1 when omitted.
Region string
}
Config configures a Client.
If AccessKeyID and SecretAccessKey are left empty, s3kit uses the AWS SDK v2 default credential chain. When Endpoint is set, s3kit assumes a generic S3-compatible service and enables path-style addressing automatically.
type ObjectVersion ¶ added in v0.0.3
type ObjectVersion struct {
VersionNumber int
VersionID string
IsLatest bool
LastModified time.Time
Size int64
ETag string
}
ObjectVersion 描述对象的一个可读取历史版本。
VersionNumber 使用从 1 开始的序号:1 表示最新对象版本,2 表示上一个对象版本,以此类推。
type ObjectVersionIdentifier ¶ added in v0.0.3
ObjectVersionIdentifier 标识一个指定 VersionID 的对象历史版本。
type ObjectVersionNumberIdentifier ¶ added in v0.0.3
ObjectVersionNumberIdentifier 标识一个指定版本号的对象历史版本。
type SnowballAutoExtractTransferOptions ¶ added in v0.0.4
type SnowballAutoExtractTransferOptions struct {
// SourceBucket and SourceKey identify the remote archive object to read when
// SourceURL is empty.
SourceBucket string
SourceKey string
// SourceURL is an optional HTTP(S) or presigned S3 URL. When set,
// SourceBucket is not required and source may be nil.
SourceURL string
// DestinationBucket and DestinationKey identify where the archive is
// uploaded on the MinIO target.
DestinationBucket string
DestinationKey string
// ContentType optionally overrides the uploaded archive content type. Leave
// empty to infer from SourceKey or SourceURL.
ContentType string
}
SnowballAutoExtractTransferOptions configures TransferSnowballAutoExtract.