Directly assign URL variables
This commit is contained in:
parent
ac760626b3
commit
42d005eb82
4 changed files with 9 additions and 9 deletions
|
@ -10,8 +10,6 @@ import (
|
||||||
// CreateObjectHandler allows to upload a new object
|
// CreateObjectHandler allows to upload a new object
|
||||||
func CreateObjectHandler(s3 S3Client) http.Handler {
|
func CreateObjectHandler(s3 S3Client) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
|
||||||
|
|
||||||
err := r.ParseMultipartForm(32 << 20)
|
err := r.ParseMultipartForm(32 << 20)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleHTTPError(w, http.StatusUnprocessableEntity, err)
|
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 {
|
if err != nil {
|
||||||
handleHTTPError(w, http.StatusInternalServerError, err)
|
handleHTTPError(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -9,9 +9,8 @@ import (
|
||||||
// DeleteBucketHandler deletes a bucket
|
// DeleteBucketHandler deletes a bucket
|
||||||
func DeleteBucketHandler(s3 S3Client) http.Handler {
|
func DeleteBucketHandler(s3 S3Client) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
bucketName := mux.Vars(r)["bucketName"]
|
||||||
|
err := s3.RemoveBucket(bucketName)
|
||||||
err := s3.RemoveBucket(vars["bucketName"])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleHTTPError(w, http.StatusInternalServerError, err)
|
handleHTTPError(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -10,8 +10,9 @@ import (
|
||||||
func DeleteObjectHandler(s3 S3Client) http.Handler {
|
func DeleteObjectHandler(s3 S3Client) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
bucketName := vars["bucketName"]
|
||||||
err := s3.RemoveObject(vars["bucketName"], vars["objectName"])
|
objectName := vars["objectName"]
|
||||||
|
err := s3.RemoveObject(bucketName, objectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleHTTPError(w, http.StatusInternalServerError, err)
|
handleHTTPError(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,9 +12,10 @@ import (
|
||||||
func GetObjectHandler(s3 S3Client) http.Handler {
|
func GetObjectHandler(s3 S3Client) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
bucketName := vars["bucketName"]
|
||||||
objectName := vars["objectName"]
|
objectName := vars["objectName"]
|
||||||
|
|
||||||
object, err := s3.GetObject(vars["bucketName"], objectName)
|
object, err := s3.GetObject(bucketName, objectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleHTTPError(w, http.StatusInternalServerError, err)
|
handleHTTPError(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue