in src/statequery/reservations.go [67:106]
func retrieveReservationLocation(ctx context.Context, client *reservationSDK.Client, project string, location string, ch chan<- Reservation, wg *sync.WaitGroup) {
// Defer completion signal on wait group
defer wg.Done()
fmt.Printf("Checking -> projects/%s/locations/%s", project, location)
// Create request on specific location
request := &reservationPB.ListReservationsRequest{
Parent: fmt.Sprintf("projects/%s/locations/%s", project, location),
}
// Execute API call and depaginate responses
it := client.ListReservations(ctx, request)
for {
response, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
log.Printf("error retrieving reservations: %v\n", err)
break
}
// Break up full reservation resource ID
tokens := strings.Split(response.Name, "/")
name := tokens[len(tokens)-1]
if name == "default" {
// Skip default (on-demand) reservation
continue
}
log.Printf("found reservation: %s\n", response.Name)
// Push reservation down the channel
ch <- Reservation{
Name: name,
Slots: float64(response.SlotCapacity),
Location: location,
}
}
}