s3manager-web/internal/app/s3manager/delete_object.go

26 lines
597 B
Go
Raw Normal View History

2017-05-08 23:07:07 +02:00
package s3manager
2017-03-30 22:48:27 +02:00
import (
2019-09-05 00:44:02 +02:00
"fmt"
2017-03-30 22:48:27 +02:00
"net/http"
2018-05-31 16:10:41 +02:00
"github.com/matryer/way"
2021-08-05 11:44:40 +02:00
"github.com/minio/minio-go/v7"
2017-03-30 22:48:27 +02:00
)
2018-05-31 16:10:41 +02:00
// HandleDeleteObject deletes an object.
func HandleDeleteObject(s3 S3) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
bucketName := way.Param(r.Context(), "bucketName")
objectName := way.Param(r.Context(), "objectName")
2018-03-14 21:53:35 +01:00
2021-08-05 11:44:40 +02:00
err := s3.RemoveObject(r.Context(), bucketName, objectName, minio.RemoveObjectOptions{})
2017-03-30 22:48:27 +02:00
if err != nil {
2019-09-05 00:44:02 +02:00
handleHTTPError(w, fmt.Errorf("error removing object: %w", err))
2017-03-30 22:48:27 +02:00
return
}
2017-04-10 14:19:27 +02:00
w.WriteHeader(http.StatusNoContent)
2018-05-31 16:10:41 +02:00
}
2017-03-30 22:48:27 +02:00
}