-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
37 lines (31 loc) · 982 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
package dynamo_node_repository
import (
"context"
"github.com/awlsring/texit/internal/pkg/domain/node"
"github.com/awlsring/texit/internal/pkg/logger"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
)
func (d *DynamoNodeRepository) List(ctx context.Context) ([]*node.Node, error) {
log := logger.FromContext(ctx)
log.Debug().Msg("Listing nodes from DynamoDB")
log.Debug().Msg("Scanning DynamoDB table")
resp, err := d.client.Scan(ctx, &dynamodb.ScanInput{
TableName: &d.table,
})
if err != nil {
log.Error().Err(err).Msg("Error listing nodes from DynamoDB")
return nil, err
}
log.Debug().Msg("Scanned DynamoDB table")
nodes := make([]*node.Node, 0, len(resp.Items))
for _, item := range resp.Items {
node, err := recordFromDdb(item)
if err != nil {
log.Error().Err(err).Msg("Error unmarshalling node from DynamoDB")
return nil, err
}
nodes = append(nodes, node.ToNode())
}
log.Debug().Msg("Listed nodes from DynamoDB")
return nodes, nil
}