-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.go
40 lines (33 loc) · 839 Bytes
/
entity.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
package transformer
import "cloud.google.com/go/datastore"
var _ datastore.KeyLoader = &Entity{}
// Entity contains Key and properties of a datastore entity
//
// Implements datastore.KeyLoader in order to Load and Save
// the entity.
type Entity struct {
Key *datastore.Key
Properties map[string]datastore.Property
}
func (e *Entity) LoadKey(k *datastore.Key) error {
e.Key = k
return nil
}
func (e *Entity) Load(props []datastore.Property) error {
for _, p := range props {
e.Properties[p.Name] = p
}
return nil
}
func (e *Entity) Save() ([]datastore.Property, error) {
props := make([]datastore.Property, 0, len(e.Properties))
for _, p := range e.Properties {
props = append(props, p)
}
return props, nil
}
func newEntity() *Entity {
return &Entity{
Properties: make(map[string]datastore.Property),
}
}