s3manager-web/create_bucket.go

37 lines
792 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 (
"encoding/json"
"net/http"
minio "github.com/minio/minio-go"
)
2017-05-08 23:07:07 +02:00
// CreateBucketHandler creates a new bucket.
func CreateBucketHandler(s3 S3) http.Handler {
2017-03-30 22:48:27 +02:00
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var bucket minio.BucketInfo
err := json.NewDecoder(r.Body).Decode(&bucket)
if err != nil {
2017-04-09 16:28:57 +02:00
handleHTTPError(w, http.StatusUnprocessableEntity, err)
2017-03-30 22:48:27 +02:00
return
}
err = s3.MakeBucket(bucket.Name, "")
if err != nil {
2017-04-09 16:28:57 +02:00
handleHTTPError(w, http.StatusInternalServerError, err)
2017-03-30 22:48:27 +02:00
return
}
2017-05-08 23:07:07 +02:00
w.Header().Set(HeaderContentType, ContentTypeJSON)
2017-03-30 22:48:27 +02:00
w.WriteHeader(http.StatusCreated)
err = json.NewEncoder(w).Encode(bucket)
if err != nil {
2017-04-09 16:28:57 +02:00
handleHTTPError(w, http.StatusInternalServerError, err)
2017-03-30 22:48:27 +02:00
return
}
})
}