-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
example_test.go
67 lines (62 loc) · 1.82 KB
/
example_test.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
package dynamo_test
import (
"context"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/retry"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/guregu/dynamo/v2"
)
func ExampleNew() {
// Basic setup example.
// See: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/config for more on configuration options.
const region = "us-west-2"
cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion(region),
)
if err != nil {
log.Fatal(err)
}
db := dynamo.New(cfg)
// use the db
_ = db
}
func ExampleNew_local_endpoint() {
// Example of connecting to a DynamoDB local instance.
// See: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html
const endpoint = "http://localhost:8000"
resolver := aws.EndpointResolverWithOptionsFunc(
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{URL: endpoint}, nil
},
)
// credentials can be anything, but must be set
creds := credentials.NewStaticCredentialsProvider("dummy", "dummy", "")
cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion("local"), // region can also be anything
config.WithEndpointResolverWithOptions(resolver),
config.WithCredentialsProvider(creds),
)
if err != nil {
log.Fatal(err)
}
db := dynamo.New(cfg)
// use the db
_ = db
}
func ExampleRetryTxConflicts() {
// `dynamo.RetryTxConflicts` is an option you can pass to retry.NewStandard.
// It will automatically retry canceled transactions.
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRetryer(func() aws.Retryer {
return retry.NewStandard(dynamo.RetryTxConflicts)
}))
if err != nil {
log.Fatal(err)
}
db := dynamo.New(cfg)
// use the db
_ = db
}