2017-04-03 14:08:01 +02:00
|
|
|
package main
|
2017-03-30 22:48:27 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
minio "github.com/minio/minio-go"
|
|
|
|
)
|
|
|
|
|
2017-04-03 14:08:01 +02:00
|
|
|
// CreateBucketHandler creates a new bucket
|
|
|
|
func CreateBucketHandler(s3 S3Client) 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-04-07 10:07:23 +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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|