Is
Overview
Is reports whether err matches target in the error chain.
Part of the err package — Node.js analog: http-errors.
Signature
go
func Is(err, target error) boolCompare: Node.js · Standard Go · gox
js
// Typical http-errors pattern in Node.jsgo
errors.Is(err, target)
errors.As(err, &target)
fmt.Errorf("context: %w", err)go
import "github.com/sahilkhaire/gox/err"
if err.Is(err, target) { /* ... */ }Example
go
import "github.com/sahilkhaire/gox/err"
if err.Is(err, target) { /* ... */ }Tips
Import github.com/sahilkhaire/gox/err and call Is directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
errors.Is(err, target)
errors.As(err, &target)
fmt.Errorf("context: %w", err)