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
Since Go 1.18 and introduced generics, method errors.As seems a little out of place as from API consumer it requires creating error variable along with if check, which cannot be done simply in one line, it even becomes more robust when more error assertions are done.
So general idea is to introduce in Golang with generics more general format of performing errors.As, today implemented something like this using generics to make API even more user friendly for one-lining it in if statements.
func ErrorAs[T error](source error) (T, bool) {
var out T
isErr := errors.As(source, &out)
return out, isErr
}
The text was updated successfully, but these errors were encountered:
Hello!
Since Go 1.18 and introduced generics, method
errors.As
seems a little out of place as from API consumer it requires creating error variable along with if check, which cannot be done simply in one line, it even becomes more robust when more error assertions are done.So general idea is to introduce in Golang with generics more general format of performing
errors.As
, today implemented something like this using generics to make API even more user friendly for one-lining it in if statements.The text was updated successfully, but these errors were encountered: