-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashes.go
85 lines (77 loc) · 2.25 KB
/
hashes.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
package main
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
v1 "github.com/dbProjectRED/redimo/v1"
"github.com/golang/protobuf/ptypes/any"
)
func (r RedimoService) HGet(ctx context.Context, request *v1.HGetRequest) (*v1.HGetResponse, error) {
resp, err := request.GetTable().Client().GetItemRequest(&dynamodb.GetItemInput{
ConsistentRead: aws.Bool(true),
Key: map[string]dynamodb.AttributeValue{
"pk": {
S: aws.String(request.GetKey()),
},
"sk": {
S: aws.String(request.GetFieldName()),
},
},
ReturnConsumedCapacity: dynamodb.ReturnConsumedCapacityTotal,
TableName: aws.String(request.GetTable().GetTable()),
}).Send(ctx)
if err != nil {
return nil, err
}
return &v1.HGetResponse{
Found: len(resp.Item) > 0,
Value: &any.Any{
TypeUrl: aws.StringValue(resp.Item["type"].S),
Value: resp.Item["data"].B,
},
}, nil
}
func (r RedimoService) HSet(ctx context.Context, request *v1.HSetRequest) (*v1.HSetResponse, error) {
_, err := request.GetTable().Client().PutItemRequest(&dynamodb.PutItemInput{
Item: map[string]dynamodb.AttributeValue{
"pk": {
S: aws.String(request.GetKey()),
},
"sk": {
S: aws.String(request.GetFieldName()),
},
"type": {
S: aws.String(request.GetValue().GetTypeUrl()),
},
"data": {
B: request.GetValue().GetValue(),
},
},
ReturnConsumedCapacity: dynamodb.ReturnConsumedCapacityTotal,
ReturnValues: dynamodb.ReturnValueNone,
TableName: aws.String(request.GetTable().GetTable()),
}).Send(ctx)
if err != nil {
return nil, err
}
return &v1.HSetResponse{}, nil
}
func (r RedimoService) HDel(ctx context.Context, request *v1.HDelRequest) (*v1.HDelResponse, error) {
_, err := request.GetTable().Client().DeleteItemRequest(&dynamodb.DeleteItemInput{
Key: map[string]dynamodb.AttributeValue{
"pk": {
S: aws.String(request.GetKey()),
},
"sk": {
S: aws.String(request.GetFieldName()),
},
},
ReturnConsumedCapacity: dynamodb.ReturnConsumedCapacityTotal,
ReturnValues: dynamodb.ReturnValueNone,
TableName: aws.String(request.GetTable().GetTable()),
}).Send(ctx)
if err != nil {
return nil, err
}
return &v1.HDelResponse{}, nil
}