func readFile() error { return &os.PathError{Op: "read", Path: "/a/b", Err: errors.New("read error")} } func main() { err := readFile() // การ assert type แบบเดิม if e, ok := err.(*os.PathError); ok { fmt.Printf("type assertion, error match os.PathError: %#v\n", e) } // เปลี่ยนมาใช้ฟังก์ชั่น As var e *os.PathError if errors.As(err, &e) { fmt.Printf("type assertion, error match os.PathError: %#v\n", e) } }