/
default.go
72 lines (57 loc) · 1.57 KB
/
default.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
63
64
65
66
67
68
69
70
71
72
package record
import (
"github.com/whosonfirst/go-whosonfirst-inspector"
"github.com/whosonfirst/go-whosonfirst-inspector/utils"
_ "log"
"time"
)
type DefaultRecord struct {
catalog.Record `json:",omitempty"`
RecordType string `json:"type"`
RecordSource string `json:"source"`
RecordID int64 `json:"id"`
RecordURI string `json:"uri"`
RecordBody interface{} `json:"body"`
RecordHash string `json:"hash"`
RecordTiming time.Duration `json:"timing"`
RecordLastModified int64 `json:"lastmodified"`
}
func (r *DefaultRecord) Id() int64 {
return r.RecordID
}
func (r *DefaultRecord) Type() string {
return r.RecordType
}
func (r *DefaultRecord) Source() string {
return r.RecordSource
}
func (r *DefaultRecord) URI() string {
return r.RecordURI
}
func (r *DefaultRecord) Body() interface{} {
return r.RecordBody
}
func (r *DefaultRecord) Timing() time.Duration {
return r.RecordTiming
}
func (r *DefaultRecord) LastModified() int64 {
return r.RecordLastModified
}
func NewDefaultRecord(rtype string, source string, id int64, uri string, body interface{}, t time.Duration) (catalog.Record, error) {
hash, err := utils.HashInterface(body)
if err != nil {
return nil, err
}
lastmod := LastModified(body)
r := DefaultRecord{
RecordType: rtype,
RecordSource: source,
RecordID: id,
RecordURI: uri,
RecordBody: body,
RecordHash: hash,
RecordLastModified: lastmod,
RecordTiming: t,
}
return &r, nil
}