-
Notifications
You must be signed in to change notification settings - Fork 35
/
list.go
38 lines (32 loc) · 779 Bytes
/
list.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
package nameserver
import (
"context"
"encoding/json"
"github.com/containerd/containerd/errdefs"
api "github.com/ehazlett/stellar/api/services/nameserver/v1"
)
func (s *service) List(ctx context.Context, req *api.ListRequest) (*api.ListResponse, error) {
c, err := s.client(s.agent.Self().Address)
if err != nil {
return nil, err
}
defer c.Close()
kvs, err := c.Datastore().Search(dsNameserverBucketName, "*")
if err != nil {
err = errdefs.FromGRPC(err)
if !errdefs.IsNotFound(err) {
return nil, err
}
}
var records []*api.Record
for _, kv := range kvs {
var r []*api.Record
if err := json.Unmarshal(kv.Value, &r); err != nil {
return nil, err
}
records = append(records, r...)
}
return &api.ListResponse{
Records: records,
}, nil
}