diff options
author | Eli Bendersky <eliben@golang.org> | 2021-06-29 16:31:18 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-06-30 16:44:19 +0000 |
commit | 0fa3265fe14c775668fc8272f47adf4fbaa60bac (patch) | |
tree | 9dddeb0abf60ee7edaf6d6c8b83b9b9d3f6230d7 /src/os | |
parent | d19a53338fa6272b4fe9c39d66812a79e1464cd2 (diff) | |
download | go-0fa3265fe14c775668fc8272f47adf4fbaa60bac.tar.gz go-0fa3265fe14c775668fc8272f47adf4fbaa60bac.zip |
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>
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/example_test.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/os/example_test.go b/src/os/example_test.go index 3adce51784..e8554b0b12 100644 --- a/src/os/example_test.go +++ b/src/os/example_test.go @@ -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: |