OLD | NEW |
(Empty) | |
| 1 import 'dart:async'; |
| 2 |
| 3 import 'package:googleapis_auth/auth_io.dart' as auth; |
| 4 import 'package:gcloud/storage.dart'; |
| 5 import 'package:gcloud/http.dart'; |
| 6 import 'package:gcloud/service_scope.dart' as ss; |
| 7 |
| 8 Future runApp() { |
| 9 // The `runApp` function runs inside a context and can therefore |
| 10 // access any registered values. In this case we use the `storage` |
| 11 // object. But the `authenticatedClient` object is available as well. |
| 12 return storageService.listBucketNames().listen(print).asFuture(); |
| 13 } |
| 14 |
| 15 main() { |
| 16 // Assumes we are running on a ComputeEngine VM with the storage scopes |
| 17 // enabled. |
| 18 auth.clientViaMetadataServer().then((httpClient) { |
| 19 // Creates a new context and runs the given closure inside it. |
| 20 ss.fork(() { |
| 21 ss.registerScopeExitCallback(httpClient.close); |
| 22 |
| 23 // We register the HTTP client. |
| 24 registerAuthClientService(httpClient); |
| 25 |
| 26 // We register the storage object inside the newly created service scope. |
| 27 // This makes it available to all code running inside this context. |
| 28 registerStorageService(new Storage(httpClient, 'my-project-id')); |
| 29 return runApp(); |
| 30 }); |
| 31 }); |
| 32 } |
OLD | NEW |