-
Notifications
You must be signed in to change notification settings - Fork 5
/
example_aws-dynamodb_get-item.go
45 lines (40 loc) · 1.66 KB
/
example_aws-dynamodb_get-item.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
package main
import (
"fmt"
"github.com/btnguyen2k/prom"
"math/rand"
"strconv"
"time"
)
func awsDynamodbGetItem(adc *prom.AwsDynamodbConnect, table string, filter map[string]interface{}) {
fmt.Printf(" Loading an item from table [%s] with filter: %v\n", table, filter)
result, err := adc.GetItem(nil, table, filter)
if err != nil {
fmt.Printf(" Error: %e\n", err)
} else if result == nil {
fmt.Printf(" Item not found with filter: %v\n", filter)
} else {
fmt.Printf(" Item: %s\n", toJsonDynamodb(result))
}
}
func main() {
rand.Seed(time.Now().UnixNano())
adc := createAwsDynamodbConnect("ap-southeast-1")
defer adc.Close()
fmt.Println("-== Get Single Item from Table ==-")
awsDynamodbGetItem(adc, "test1", map[string]interface{}{"username": "user-0"})
awsDynamodbGetItem(adc, "test1", map[string]interface{}{"username": "user-not-exist"})
awsDynamodbGetItem(adc, "test1", map[string]interface{}{"email": "email-0@test.com"})
for i := 0; i < awsDynamodbRandomRange; i++ {
awsDynamodbGetItem(adc, "test1", map[string]interface{}{"username": "user-2", "email": "email-" + strconv.Itoa(i) + "@test.com"})
}
fmt.Println(awsDynamodbSep)
fmt.Println("-== Get Single Item from Table ==-")
awsDynamodbGetItem(adc, "test2", map[string]interface{}{"username": "user-0"})
awsDynamodbGetItem(adc, "test2", map[string]interface{}{"username": "user-not-exist"})
awsDynamodbGetItem(adc, "test2", map[string]interface{}{"email": "email-0@test.com"})
for i := 0; i < awsDynamodbRandomRange; i++ {
awsDynamodbGetItem(adc, "test2", map[string]interface{}{"username": "user-2", "email": "email-" + strconv.Itoa(i) + "@test.com"})
}
fmt.Println(awsDynamodbSep)
}