MCPcopy Create free account
hub / github.com/google/go-cloud / Example_stringDecoder

Function Example_stringDecoder

runtimevar/example_test.go:67–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67func Example_stringDecoder() {
68 // Construct a *Variable using a constructor from one of the
69 // runtimevar subpackages. This example uses constantvar.
70 // The variable value is of type string, so we use StringDecoder.
71 v := constantvar.NewBytes([]byte("hello world"), runtimevar.StringDecoder)
72 defer v.Close()
73
74 // Call Latest to retrieve the value.
75 snapshot, err := v.Latest(context.Background())
76 if err != nil {
77 log.Fatalf("Error in retrieving variable: %v", err)
78 }
79 // snapshot.Value will be of type string.
80 fmt.Printf("%q\n", snapshot.Value.(string))
81
82 // Output:
83 // "hello world"
84}
85
86func ExampleVariable_Latest() {
87 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.

Callers

nothing calls this directly

Calls 3

NewBytesFunction · 0.92
LatestMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected