|
|
|
@ -6,16 +6,29 @@ import ( |
|
|
|
|
"io" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Storage struct{} |
|
|
|
|
type Storage struct { |
|
|
|
|
data map[string][]byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) error { |
|
|
|
|
// TODO synchronize access
|
|
|
|
|
// get object
|
|
|
|
|
objectData := "OBJECT: " + bucket + " - " + object |
|
|
|
|
objectBuffer := bytes.NewBufferString(objectData) |
|
|
|
|
// copy object to writer
|
|
|
|
|
_, err := io.Copy(w, objectBuffer) |
|
|
|
|
return err |
|
|
|
|
key := bucket + ":" + object |
|
|
|
|
if val, ok := storage.data[key]; ok { |
|
|
|
|
objectBuffer := bytes.NewBuffer(val) |
|
|
|
|
_, err := io.Copy(w, objectBuffer) |
|
|
|
|
return err |
|
|
|
|
} else { |
|
|
|
|
return errors.New("Not Found") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (storage *Storage) StoreObject(bucket string, object string, data io.Reader) { |
|
|
|
|
key := bucket + ":" + object |
|
|
|
|
var bytesBuffer bytes.Buffer |
|
|
|
|
if _, ok := io.Copy(&bytesBuffer, data); ok == nil { |
|
|
|
|
storage.data[key] = bytesBuffer.Bytes() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Start() (chan<- string, <-chan error, *Storage) { |
|
|
|
|