From: Adrian Hesketh Date: Sun, 30 Jan 2022 19:11:32 +0000 (+0000) Subject: os: add examples for Mkdir and MkdirAll X-Git-Tag: go1.18rc1~69 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0b7e586e485d4790b240354513acbb8438bb842f;p=gostls13.git os: add examples for Mkdir and MkdirAll Provides example using value for the perm argument that matches the value set by the mkdir command on MacOS and Linux. Change-Id: I98d9ac9668de4dc0efde2484f5b00d005628ac9e GitHub-Last-Rev: 44e617912f3604f4cc05a946d76cd3020acfd722 GitHub-Pull-Request: golang/go#50641 Reviewed-on: https://go-review.googlesource.com/c/go/+/378874 Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Trust: Cherry Mui --- diff --git a/src/os/example_test.go b/src/os/example_test.go index e8554b0b12..53e3c5227b 100644 --- a/src/os/example_test.go +++ b/src/os/example_test.go @@ -241,3 +241,25 @@ func ExampleWriteFile() { log.Fatal(err) } } + +func ExampleMkdir() { + err := os.Mkdir("testdir", 0750) + if err != nil && !os.IsExist(err) { + log.Fatal(err) + } + err = os.WriteFile("testdir/testfile.txt", []byte("Hello, Gophers!"), 0660) + if err != nil { + log.Fatal(err) + } +} + +func ExampleMkdirAll() { + err := os.MkdirAll("test/subdir", 0750) + if err != nil && !os.IsExist(err) { + log.Fatal(err) + } + err = os.WriteFile("test/subdir/testfile.txt", []byte("Hello, Gophers!"), 0660) + if err != nil { + log.Fatal(err) + } +}