You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This requires Go 1.18+ be the minimum supported version for clients.
The Iterator interface has worked great but the generated code in GAPICs for it is kind of messy and confusing. With generics, we could create explore more general implementations that were more streamlined. For example (copied from internal link):
// Playing with https://github.com/golang/go/discussions/54245// -----------------------------------------------------------------------------// in standard librarytypeIter2[E1, E2any] interface {
Next() (E1, E2, bool)
}
// -----------------------------------------------------------------------------// in client library// existingtypeSecretstruct{}
typeSecretIteratorstruct{}
func (it*SecretIterator) Next() (*Secret, error) { returnnil, nil }
// Newfunc (it*SecretIterator) Range() Iter2[*Secret, error] {
returnNewStdIter[*Secret](it)
}
// -----------------------------------------------------------------------------// in iterator package// existingvarDone=fmt.Errorf("done")
// New// Nexter is an interface all client library iterators implement.typeNexter[Tany] interface {
Next() (T, error)
}
funcNewStdIter[Tany](fromNexter[T]) Iter2[T, error] {
returnstdIteratorAdapter[T]{from}
}
typestdIteratorAdapter[Tany] struct {
nNexter[T]
}
func (nstdIteratorAdapter[T]) Next() (T, error, bool) {
r, err:=n.n.Next()
iferr==Done {
varzeroTreturnzero, nil, false
}
returnr, err, err==nil
}
// -----------------------------------------------------------------------------// Old usageit:=c.ListSecrets(ctx, req)
for {
resp, err:=it.Next()
iferr==iterator.Done {
break
}
iferr!=nil {
// TODO: Handle error.
}
// TODO: Use resp._=resp
}
// New usageforresp, err:=rangec.ListSecrets(ctx, req) {
iferr!=nil {
// TODO: Handle error.
}
// TODO: Use resp._=resp
}
The text was updated successfully, but these errors were encountered:
This requires Go 1.18+ be the minimum supported version for clients.
The
Iterator
interface has worked great but the generated code in GAPICs for it is kind of messy and confusing. With generics, we could create explore more general implementations that were more streamlined. For example (copied from internal link):The text was updated successfully, but these errors were encountered: