Merge pull request #21 from fkautz/pr_out_adding_error_handling_to_storage_get_call

master
Frederick F. Kautz IV 10 years ago
commit 50703cf4d6
  1. 19
      pkg/storage/storage.go
  2. 20
      pkg/webapi/minioapi/minioapi.go

@ -10,16 +10,27 @@ type Storage struct {
data map[string][]byte data map[string][]byte
} }
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) error { type GenericError struct {
bucket string
path string
}
type ObjectNotFound GenericError
func (self ObjectNotFound) Error() string {
return "Not Found: " + self.bucket + "#" + self.path
}
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error) {
// TODO synchronize access // TODO synchronize access
// get object // get object
key := bucket + ":" + object key := bucket + ":" + object
if val, ok := storage.data[key]; ok { if val, ok := storage.data[key]; ok {
objectBuffer := bytes.NewBuffer(val) objectBuffer := bytes.NewBuffer(val)
_, err := io.Copy(w, objectBuffer) written, err := io.Copy(w, objectBuffer)
return err return written, err
} else { } else {
return errors.New("Not Found") return 0, ObjectNotFound{bucket: bucket, path: object}
} }
} }

@ -1,6 +1,7 @@
package minioapi package minioapi
import ( import (
"log"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -25,7 +26,24 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques
vars := mux.Vars(req) vars := mux.Vars(req)
bucket := vars["bucket"] bucket := vars["bucket"]
object := vars["object"] object := vars["object"]
server.storage.CopyObjectToWriter(w, bucket, object)
_, err := server.storage.CopyObjectToWriter(w, bucket, object)
switch err := err.(type) {
case nil: // success
{
log.Println("Found: " + bucket + "#" + object)
}
case mstorage.ObjectNotFound:
{
log.Println(err)
w.WriteHeader(http.StatusNotFound)
}
default:
{
log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
}
}
} }
func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) {

Loading…
Cancel
Save