diff --git a/lectures/02-interfaces/lecture.slide b/lectures/02-interfaces/lecture.slide index 5dae78b..a2006cd 100644 --- a/lectures/02-interfaces/lecture.slide +++ b/lectures/02-interfaces/lecture.slide @@ -475,3 +475,7 @@ As if perr, ok := err.(*os.PathError); ok { fmt.Println(perr.Path) } + +* errors.As + +.play temporary/main.go diff --git a/lectures/02-interfaces/temporary/main.go b/lectures/02-interfaces/temporary/main.go new file mode 100644 index 0000000..056b0f8 --- /dev/null +++ b/lectures/02-interfaces/temporary/main.go @@ -0,0 +1,18 @@ +package main + +import "errors" + +type Temporary interface { + IsTemporary() bool +} + +func do() error { return nil } + +func main() { + err := do() + + var terr Temporary + if errors.As(err, &terr) && terr.IsTemporary() { + //... + } +}