Exemplo n.º 1
0
// createRemoveHandler returns the handler that removes blob a single blob at path
func createRemoveHandler(storage blobserver.Storage) http.Handler {
	return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		res, err := handleRemove(r, storage)
		if err != nil {
			httputil.ServeJSONError(rw, err)
		} else {
			httputil.ReturnJSON(rw, res)
		}
	})
}
Exemplo n.º 2
0
// createUploadHandler returns the handler that receives multi-part form uploads.
func createUploadHandler(storage blobserver.Storage) http.Handler {
	return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		res, err := handleMultiPartUpload(r, storage)
		if err != nil {
			log.Errorf("upload: %v", err)
			httputil.ServeJSONError(rw, err)
		} else {
			httputil.ReturnJSONCode(rw, http.StatusCreated, res)
		}
	})
}
Exemplo n.º 3
0
func createStatHandler(storage blobserver.BlobStatter) http.Handler {
	return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		req.ParseForm()
		vars := mux.Vars(req)
		res, err := handleStat(req, storage, []string{vars["blobRef"]})

		if err != nil {
			httputil.ServeJSONError(rw, err)
		} else {
			httputil.ReturnJSON(rw, res)
		}
	})
}
Exemplo n.º 4
0
func createBatchStatHandler(storage blobserver.BlobStatter) http.Handler {
	return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		req.ParseForm()
		blobs, _ := req.Form["blob"]
		res, err := handleStat(req, storage, blobs)

		if err != nil {
			httputil.ServeJSONError(rw, err)
		} else {
			httputil.ReturnJSON(rw, res)
		}
	})
}