s3manager-web/create_bucket.go
2017-05-25 18:40:34 +02:00

37 lines
817 B
Go

package s3manager
import (
"encoding/json"
"net/http"
minio "github.com/minio/minio-go"
"github.com/pkg/errors"
)
// CreateBucketHandler creates a new bucket.
func CreateBucketHandler(s3 S3) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var bucket minio.BucketInfo
err := json.NewDecoder(r.Body).Decode(&bucket)
if err != nil {
handleHTTPError(w, errors.Wrap(err, errDecodingBody))
return
}
err = s3.MakeBucket(bucket.Name, "")
if err != nil {
handleHTTPError(w, errors.Wrap(err, "error making bucket"))
return
}
w.Header().Set(HeaderContentType, ContentTypeJSON)
w.WriteHeader(http.StatusCreated)
err = json.NewEncoder(w).Encode(bucket)
if err != nil {
handleHTTPError(w, errors.Wrap(err, errEncodingJSON))
return
}
})
}