| 65 | } |
| 66 | |
| 67 | func 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 | |
| 86 | func ExampleVariable_Latest() { |
| 87 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |