Directly assign URL variables

This commit is contained in:
Lena Fuhrimann 2017-04-21 15:42:00 +02:00
parent ac760626b3
commit 42d005eb82
4 changed files with 9 additions and 9 deletions

View file

@ -10,8 +10,6 @@ import (
// CreateObjectHandler allows to upload a new object
func CreateObjectHandler(s3 S3Client) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
err := r.ParseMultipartForm(32 << 20)
if err != nil {
handleHTTPError(w, http.StatusUnprocessableEntity, err)
@ -30,7 +28,8 @@ func CreateObjectHandler(s3 S3Client) http.Handler {
}
}()
_, err = s3.PutObject(vars["bucketName"], handler.Filename, file, contentTypeOctetStream)
bucketName := mux.Vars(r)["bucketName"]
_, err = s3.PutObject(bucketName, handler.Filename, file, contentTypeOctetStream)
if err != nil {
handleHTTPError(w, http.StatusInternalServerError, err)
return

View file

@ -9,9 +9,8 @@ import (
// DeleteBucketHandler deletes a bucket
func DeleteBucketHandler(s3 S3Client) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
err := s3.RemoveBucket(vars["bucketName"])
bucketName := mux.Vars(r)["bucketName"]
err := s3.RemoveBucket(bucketName)
if err != nil {
handleHTTPError(w, http.StatusInternalServerError, err)
return

View file

@ -10,8 +10,9 @@ import (
func DeleteObjectHandler(s3 S3Client) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
err := s3.RemoveObject(vars["bucketName"], vars["objectName"])
bucketName := vars["bucketName"]
objectName := vars["objectName"]
err := s3.RemoveObject(bucketName, objectName)
if err != nil {
handleHTTPError(w, http.StatusInternalServerError, err)
return

View file

@ -12,9 +12,10 @@ import (
func GetObjectHandler(s3 S3Client) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bucketName := vars["bucketName"]
objectName := vars["objectName"]
object, err := s3.GetObject(vars["bucketName"], objectName)
object, err := s3.GetObject(bucketName, objectName)
if err != nil {
handleHTTPError(w, http.StatusInternalServerError, err)
return