example_Into_test.go 335 B

12345678910111213141516171819202122
  1. //go:build go1.18
  2. package errors_test
  3. import (
  4. "fmt"
  5. "os"
  6. "github.com/go-faster/errors"
  7. )
  8. func ExampleInto() {
  9. _, err := os.Open("non-existing")
  10. if err != nil {
  11. if pathError, ok := errors.Into[*os.PathError](err); ok {
  12. fmt.Println("Failed at path:", pathError.Path)
  13. }
  14. }
  15. // Output:
  16. // Failed at path: non-existing
  17. }