-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastore.go
47 lines (35 loc) · 1.35 KB
/
datastore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package s3datastore
import (
"errors"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/crowdmob/goamz/s3"
datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
query "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/query"
)
var _ datastore.ThreadSafeDatastore = &S3Datastore{}
var errTODO = errors.New("TODO")
var ErrInvalidType = errors.New("s3 datastore: invalid type error")
type S3Datastore struct {
Client *s3.S3
Bucket string
}
func (ds *S3Datastore) Put(key datastore.Key, value interface{}) (err error) {
data, ok := value.([]byte)
if !ok {
return ErrInvalidType
}
// TODO extract perms and s3 options
return ds.Client.Bucket(ds.Bucket).Put(key.String(), data, "application/protobuf", s3.PublicRead, s3.Options{})
}
func (ds *S3Datastore) Get(key datastore.Key) (value interface{}, err error) {
return ds.Client.Bucket(ds.Bucket).Get(key.String())
}
func (ds *S3Datastore) Has(key datastore.Key) (exists bool, err error) {
return ds.Client.Bucket(ds.Bucket).Exists(key.String())
}
func (ds *S3Datastore) Delete(key datastore.Key) (err error) {
return ds.Client.Bucket(ds.Bucket).Del(key.String())
}
func (ds *S3Datastore) Query(q query.Query) (query.Results, error) {
return nil, errors.New("TODO implement query for s3 datastore?")
}
func (ds *S3Datastore) IsThreadSafe() {}