Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

46 řádky
989 B

  1. // Copyright 2018 Google Inc. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "context"
  7. "log"
  8. "golang.org/x/oauth2/google"
  9. compute "google.golang.org/api/compute/v1"
  10. )
  11. const (
  12. projectID = "some-project-id"
  13. zone = "some-zone"
  14. operationID = "some-operation-id"
  15. )
  16. func operationProgressMain() {
  17. ctx := context.Background()
  18. client, err := google.DefaultClient(ctx, compute.CloudPlatformScope)
  19. if err != nil {
  20. log.Fatal(err)
  21. }
  22. svc, err := compute.New(client)
  23. if err != nil {
  24. log.Fatal(err)
  25. }
  26. for {
  27. resp, err := svc.ZoneOperations.Get(projectID, zone, operationID).Do()
  28. if err != nil {
  29. log.Fatal(err)
  30. }
  31. // Note: the response Status may differ between APIs. The string values
  32. // checked here may need to be changed depending on the API.
  33. if resp.Status != "WORKING" && resp.Status != "QUEUED" {
  34. break
  35. }
  36. }
  37. log.Println("operation complete")
  38. }