by candiddevmike · 3y ago · 0 comments
This is `errors.As`: https://cs.opensource.google/go/go/+/refs/tags/go1.19.4:src/.... It uses reflection and type assertions and itself contains error checking (e.g. to validate that the arguments are actually error interfaces).
It looks efficient in your code because the call is compact, but this is not even close to efficient, and especially not as efficient as a switch statement.
"Obviously, the common HTTP status codes could easily be a new error type (based on int type) so the actual code could be easily extracted via errors.As, but I want to keep the example simple."