func runServices()

in code/function/function.go [177:210]


func runServices(project string, srv *run.APIService, label string) ([]*run.Service, error) {
	parent := fmt.Sprintf("projects/%s", project)
	l := fmt.Sprintf("%s=true", label)
	services := []*run.Service{}

	locations, err := srv.Projects.Locations.List(parent).Do()
	if err != nil {
		return services, fmt.Errorf("error getting Cloud Run locations: %s", err)
	}

	var wg sync.WaitGroup
	wg.Add(len(locations.Locations))

	for _, location := range locations.Locations {
		go func(loc *run.Location) error {
			defer wg.Done()

			lp := fmt.Sprintf("projects/%s/locations/%s", project, loc.LocationId)

			svcs, err := srv.Projects.Locations.Services.List(lp).LabelSelector(l).Do()
			if err != nil {
				return fmt.Errorf("error cannot get Cloud Run service for %s: %s", loc.LocationId, err)
			}

			services = append(services, svcs.Items...)

			return nil
		}(location)
	}

	wg.Wait()

	return services, nil
}