-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiploc.go
48 lines (37 loc) · 905 Bytes
/
tiploc.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
package service
import (
bolt "github.com/etcd-io/bbolt"
"github.com/peter-mount/go-kernel/v2/rest"
"github.com/peter-mount/nre-feeds/darwinref"
)
func (dr *DarwinRefService) TiplocHandler(r *rest.Rest) error {
return dr.reference.View(func(tx *bolt.Tx) error {
tpl := r.Var("id")
if location, exists := dr.reference.GetTiploc(tx, tpl); exists {
r.Status(200).
JSON().
Value(location)
} else {
r.Status(404)
}
return nil
})
}
func (dr *DarwinRefService) TiplocsHandler(r *rest.Rest) error {
tiplocs := make([]string, 0)
if err := r.Body(&tiplocs); err != nil {
return err
}
return dr.reference.View(func(tx *bolt.Tx) error {
var ary []*darwinref.Location
for _, tpl := range tiplocs {
if location, exists := dr.reference.GetTiploc(tx, tpl); exists {
ary = append(ary, location)
}
}
r.Status(200).
JSON().
Value(ary)
return nil
})
}