Debian Codegraph @

runtimevar/awsparamstore/example_test.go

raw
1 // Copyright 2018 The Go Cloud Development Kit Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package awsparamstore_test
16
17 import (
18 "context"
19 "log"
20
21 "github.com/aws/aws-sdk-go-v2/config"
22 "github.com/aws/aws-sdk-go-v2/service/ssm"
23 "gocloud.dev/runtimevar"
24 "gocloud.dev/runtimevar/awsparamstore"
25 )
26
27 func ExampleOpenVariable() {
28 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
29
30 // Establish a AWS V2 Config.
31 // See https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/ for more info.
32 ctx := context.Background()
33 cfg, err := config.LoadDefaultConfig(ctx)
34 if err != nil {
35 log.Fatal(err)
36 }
37
38 // Construct a *runtimevar.Variable that watches the variable.
39 client := ssm.NewFromConfig(cfg)
40 v, err := awsparamstore.OpenVariable(client, "cfg-variable-name", runtimevar.StringDecoder, nil)
41 if err != nil {
42 log.Fatal(err)
43 }
44 defer v.Close()
45 }
46
47 func Example_openVariableFromURL() {
48 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
49 // PRAGMA: On gocloud.dev, add a blank import: _ "gocloud.dev/runtimevar/awsparamstore"
50 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
51 ctx := context.Background()
52
53 // runtimevar.OpenVariable creates a *runtimevar.Variable from a URL.
54 v, err := runtimevar.OpenVariable(ctx, "awsparamstore://myvar?region=us-west-1&decoder=string")
55 if err != nil {
56 log.Fatal(err)
57 }
58 defer v.Close()
59 }