-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.go
62 lines (52 loc) · 1.26 KB
/
object.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package riaken_struct
import (
"errors"
)
import (
core "github.com/riaken/riaken-core"
"github.com/riaken/riaken-core/rpb"
)
var ERR_NO_CONTENT error = errors.New("no content")
type Object struct {
bucket *Bucket
coreObject *core.Object
}
// CoreObject returns the underlying riaken-core Object.
func (o *Object) CoreObject() *core.Object {
return o.coreObject
}
func (o *Object) Do(opts interface{}) *Object {
o.coreObject.Do(opts)
return o
}
func (o *Object) ContentType(ct []byte) {
o.coreObject.ContentType(ct)
}
func (o *Object) Fetch(out interface{}) (*rpb.RpbGetResp, error) {
data, err := o.coreObject.Fetch()
if err != nil {
return nil, err
}
if len(data.GetContent()) == 0 {
return data, ERR_NO_CONTENT
}
return data, o.bucket.session.marshaller.Unmarshal(data.GetContent()[0].GetValue(), out)
}
func (o *Object) Store(in interface{}) (*rpb.RpbPutResp, error) {
content, err := o.bucket.session.marshaller.Marshal(in)
if err != nil {
return nil, err
}
opts := o.coreObject.GetOpts()
if opts != nil {
opts.(*rpb.RpbPutReq).Content = content
} else {
opts = &rpb.RpbPutReq{
Content: content,
}
}
return o.coreObject.Do(opts).Store(content.GetValue())
}
func (o *Object) Delete() (bool, error) {
return o.coreObject.Delete()
}