From 2584fc7d5ba66087ab4df8176cddd76d2d94daa6 Mon Sep 17 00:00:00 2001 From: evalphobia Date: Fri, 11 Dec 2020 12:31:44 +0900 Subject: [PATCH] [s3] Refactor DeleteObject (#78) --- s3/bucket.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/s3/bucket.go b/s3/bucket.go index ee8d72a..4ae6593 100644 --- a/s3/bucket.go +++ b/s3/bucket.go @@ -254,25 +254,25 @@ func (b *Bucket) CopyFrom(srcBucket, srcPath, destPath string, opt ...CopyObject // DeleteObject deletes the object of target path. func (b *Bucket) DeleteObject(path string) error { - _, err := b.service.client.DeleteObject(&SDK.DeleteObjectInput{ + return b.deleteObject(&SDK.DeleteObjectInput{ Bucket: pointers.String(b.nameWithPrefix), Key: pointers.String(path), }) - if err != nil { - b.service.Errorf("error on `GetObject` operation; bucket=%s; error=%s;", b.nameWithPrefix, err.Error()) - } - return err } -// DeleteObject deletes the object of target path and versionId. -func (b *Bucket) DeleteObjectWithVersionId(path string, versionId string) error { - _, err := b.service.client.DeleteObject(&SDK.DeleteObjectInput{ +// DeleteObjectWithVersionID deletes the object of target path and versionId. +func (b *Bucket) DeleteObjectWithVersionID(path string, versionID string) error { + return b.deleteObject(&SDK.DeleteObjectInput{ Bucket: pointers.String(b.nameWithPrefix), Key: pointers.String(path), - VersionId: pointers.String(versionId), + VersionId: pointers.String(versionID), }) +} + +func (b *Bucket) deleteObject(in *SDK.DeleteObjectInput) error { + _, err := b.service.client.DeleteObject(in) if err != nil { - b.service.Errorf("error on `DeleteObjectWithVersionId` operation; bucket=%s; error=%s;", b.nameWithPrefix, err.Error()) + b.service.Errorf("error on `DeleteObject` operation; bucket=%s; error=%s;", b.nameWithPrefix, err.Error()) } return err }