This repository was archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstore.go
More file actions
50 lines (42 loc) · 1.31 KB
/
store.go
File metadata and controls
50 lines (42 loc) · 1.31 KB
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
package possum
import (
"encoding/json"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
)
func PutSchedules(client dynamodbiface.DynamoDBAPI, tableName string, schedules Schedules) error {
b, err := json.Marshal(schedules)
if err != nil {
return err
}
item := make(map[string]*dynamodb.AttributeValue)
item["id"] = &dynamodb.AttributeValue{S: aws.String("schedules")}
item["content"] = &dynamodb.AttributeValue{S: aws.String(string(b))}
_, err = client.PutItem(&dynamodb.PutItemInput{
TableName: aws.String(tableName),
Item: item,
ReturnConsumedCapacity: aws.String("TOTAL"),
})
return err
}
func GetSchedules(client dynamodbiface.DynamoDBAPI, tableName string) (Schedules, error) {
key := make(map[string]*dynamodb.AttributeValue)
key["id"] = &dynamodb.AttributeValue{S: aws.String("schedules")}
res, err := client.GetItem(&dynamodb.GetItemInput{
ProjectionExpression: aws.String("content"),
TableName: aws.String(tableName),
Key: key,
ReturnConsumedCapacity: aws.String("TOTAL"),
})
if err != nil {
return nil, err
}
content := res.Item["content"].S
if content == nil {
return nil, nil
}
var v Schedules
err = json.Unmarshal([]byte(*content), &v)
return v, err
}