-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.go
86 lines (68 loc) · 1.91 KB
/
record.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package external
import (
"fmt"
"github.com/paulmach/orb"
)
type Record interface {
Id() string
Name() string
// A valid Who's On First placetype (used for reverse geocoding)
Placetype() string
Namespace() string
Geometry() orb.Geometry
Properties() map[string]any
}
type ExternalRecord struct {
Record `json:",omitempty"`
ExternalProperties map[string]any `json:"properties"`
ExternalGeometry orb.Geometry `json:"geometry"`
namespace string `json:"namespace"`
placetype string `json:"placetype"`
id_key string `json:"id_key"`
name_key string `json:"name_key"`
}
type NewExternalRecordOptions struct {
Properties map[string]any
Geometry orb.Geometry
Namespace string
Placetype string
IdKey string
NameKey string
}
func NewExternalRecord(opts *NewExternalRecordOptions) (Record, error) {
_, has_id := opts.Properties[opts.IdKey]
if !has_id {
return nil, fmt.Errorf("Properties missing %s key", opts.IdKey)
}
_, has_name := opts.Properties[opts.NameKey]
if !has_name {
return nil, fmt.Errorf("Properties missing %s key", opts.NameKey)
}
r := &ExternalRecord{
ExternalProperties: opts.Properties,
ExternalGeometry: opts.Geometry,
namespace: opts.Namespace,
placetype: opts.Placetype,
id_key: opts.IdKey,
name_key: opts.NameKey,
}
return r, nil
}
func (r *ExternalRecord) Id() string {
return fmt.Sprintf("%s", r.ExternalProperties[r.id_key])
}
func (r *ExternalRecord) Name() string {
return fmt.Sprintf("%s", r.ExternalProperties[r.name_key])
}
func (r *ExternalRecord) Placetype() string {
return r.placetype
}
func (r *ExternalRecord) Namespace() string {
return r.namespace
}
func (r *ExternalRecord) Geometry() orb.Geometry {
return r.ExternalGeometry
}
func (r *ExternalRecord) Properties() map[string]any {
return r.ExternalProperties
}