Skip to content
Node: http-errorsgithub.com/sahilkhaire/gox/err

As

Overview

As finds the first error in the chain assignable to target.

Part of the err package — Node.js analog: http-errors.

Signature

go
func As(err error, target any) bool

Compare: Node.js · Standard Go · gox

js
// Typical http-errors pattern in Node.js
go
errors.Is(err, target)
errors.As(err, &target)
fmt.Errorf("context: %w", err)
go
import "github.com/sahilkhaire/gox/err"

var appErr err.AppError
if err.As(err, &appErr) { /* ... */ }

Example

go
import "github.com/sahilkhaire/gox/err"

var appErr err.AppError
if err.As(err, &appErr) { /* ... */ }

Tips

Import github.com/sahilkhaire/gox/err and call As 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)

Back to err package overview

MIT Licensed · Built for Node.js developers moving to Go