mirror of
https://github.com/golang/go
synced 2024-11-26 14:46:47 -07:00
os: change example to avoid deprecated function
The IsNotExist function is deprecated; change package example to avoid it and use the recommended way instead. Fixes #46976 Change-Id: I3c301d0a89b6bda42184df314ba8418062ca39ee Reviewed-on: https://go-review.googlesource.com/c/go/+/331692 Trust: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
d19a53338f
commit
0fa3265fe1
@ -5,6 +5,7 @@
|
||||
package os_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
@ -71,9 +72,9 @@ func ExampleFileMode() {
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleIsNotExist() {
|
||||
func ExampleErrNotExist() {
|
||||
filename := "a-nonexistent-file"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(filename); errors.Is(err, fs.ErrNotExist) {
|
||||
fmt.Println("file does not exist")
|
||||
}
|
||||
// Output:
|
||||
|
Loading…
Reference in New Issue
Block a user