-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmetadata.go
39 lines (34 loc) · 855 Bytes
/
metadata.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
package db
import (
"appengine/datastore"
"reflect"
)
type Metadata struct {
Kind string
StringID string
IntID int64
HasParent bool
Parent *datastore.Key
CacheStringID string
}
func KeyMetadata(key *datastore.Key) *Metadata {
return &Metadata{
Kind: key.Kind(),
StringID: key.StringID(),
IntID: key.IntID(),
HasParent: key.Parent() != nil,
Parent: key.Parent(),
CacheStringID: key.Encode(),
}
}
// IsAutoGenerated tells whether or not a resolved key
// is auto generated by datastore
//
// Keys are auto generated if no struct field is tagged with db:"id"
func (this *Metadata) IsAutoGenerated() bool {
return this.IntID == 0 && this.StringID == ""
}
type MetadataExtractor interface {
Accept(reflect.StructField) bool
Extract(Entity, reflect.StructField, reflect.Value) error
}