From 42d005eb8263fa4388ed6d37ffe1b27841a7049a Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Fri, 21 Apr 2017 15:42:00 +0200 Subject: [PATCH] Directly assign URL variables --- create-object.go | 5 ++--- delete-bucket.go | 5 ++--- delete-object.go | 5 +++-- get-object.go | 3 ++- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/create-object.go b/create-object.go index b182558..9ea85f3 100644 --- a/create-object.go +++ b/create-object.go @@ -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 diff --git a/delete-bucket.go b/delete-bucket.go index 49fe00f..caae0d4 100644 --- a/delete-bucket.go +++ b/delete-bucket.go @@ -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 diff --git a/delete-object.go b/delete-object.go index af5ddca..6901235 100644 --- a/delete-object.go +++ b/delete-object.go @@ -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 diff --git a/get-object.go b/get-object.go index c0908cd..aded2b8 100644 --- a/get-object.go +++ b/get-object.go @@ -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