-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.go
83 lines (56 loc) · 1.46 KB
/
export.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
package export
import (
"encoding/json"
"github.com/sfomuseum/go-sfomuseum-export/properties"
wof_export "github.com/whosonfirst/go-whosonfirst-export"
wof_exporter "github.com/whosonfirst/go-whosonfirst-export/exporter"
wof_options "github.com/whosonfirst/go-whosonfirst-export/options"
)
type SFOMuseumExporter struct {
wof_exporter.Exporter
options wof_options.Options
}
func NewDefaultOptions() (wof_options.Options, error) {
return wof_options.NewDefaultOptions()
}
func NewSFOMuseumExporter(opts wof_options.Options) (wof_exporter.Exporter, error) {
ex := SFOMuseumExporter{
options: opts,
}
return &ex, nil
}
func (ex *SFOMuseumExporter) ExportFeature(feature interface{}) ([]byte, error) {
body, err := json.Marshal(feature)
if err != nil {
return nil, err
}
return ex.Export(body)
}
func (ex *SFOMuseumExporter) Export(feature []byte) ([]byte, error) {
var err error
feature, err = Prepare(feature, ex.options)
if err != nil {
return nil, err
}
feature, err = wof_export.Format(feature, ex.options)
if err != nil {
return nil, err
}
return feature, nil
}
func Prepare(feature []byte, opts wof_options.Options) ([]byte, error) {
var err error
feature, err = wof_export.Prepare(feature, opts)
if err != nil {
return nil, err
}
feature, err = properties.EnsurePlacetype(feature)
if err != nil {
return nil, err
}
feature, err = properties.EnsureIsSFO(feature)
if err != nil {
return nil, err
}
return feature, nil
}