func list(client *pubsub.Client) ([]*pubsub.Topic, error) { ctx := context.Background() // [START list_topics] var topics []*pubsub.Topic it := client.Topics(ctx) for { topic, err := it.Next() if err == iterator.Done { break } if err != nil { return nil, err } topics = append(topics, topic) } return topics, nil // [END list_topics] }