You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
minio/pkg/storage/storage.go

48 lines
1.1 KiB

package storage
import (
"bytes"
"errors"
"io"
)
type Storage struct {
data map[string][]byte
}
func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object string) error {
// TODO synchronize access
// get object
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) {
ctrlChannel := make(chan string)
errorChannel := make(chan error)
go start(ctrlChannel, errorChannel)
return ctrlChannel, errorChannel, &Storage{
data: make(map[string][]byte),
}
}
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
errorChannel <- errors.New("STORAGE MSG")
errorChannel <- errors.New("STORAGE MSG")
errorChannel <- errors.New("STORAGE MSG")
close(errorChannel)
}