s3manager-web/objects/delete-handler.go

26 lines
590 B
Go
Raw Normal View History

2017-03-30 22:48:27 +02:00
package objects
import (
"net/http"
"github.com/gorilla/mux"
2017-04-02 17:10:36 +02:00
"github.com/mastertinner/s3-manager/datasources"
"github.com/mastertinner/s3-manager/utils"
2017-03-30 22:48:27 +02:00
)
// DeleteHandler deletes an object
2017-04-02 17:10:36 +02:00
func DeleteHandler(s3 datasources.S3Client) http.Handler {
2017-03-30 22:48:27 +02:00
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
err := s3.RemoveObject(vars["bucketName"], vars["objectName"])
if err != nil {
msg := "error removing object"
2017-04-02 17:10:36 +02:00
utils.HandleHTTPError(w, msg, err, http.StatusInternalServerError)
2017-03-30 22:48:27 +02:00
return
}
w.WriteHeader(http.StatusOK)
})
}