Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/defer/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"fmt"
"os"
"path/filepath"
)

// Suppose we wanted to create a file, write to it,
Expand All @@ -20,7 +21,8 @@ func main() {
// with `closeFile`. This will be executed at the end
// of the enclosing function (`main`), after
// `writeFile` has finished.
f := createFile("/tmp/defer.txt")
path := filepath.Join(os.TempDir(), "defer.txt")
f := createFile(path)
defer closeFile(f)
writeFile(f)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/defer/defer.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
249d0bc915e075a664be8b4e9115aa9568c8999e
nhAzhDn_jga
b3687ac676cbe21ebb53a8d864fc15649c27c4a8
9_sJ5XnikSw
4 changes: 3 additions & 1 deletion examples/reading-files/reading-files.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
)

// Reading files requires checking most calls for errors.
Expand All @@ -23,7 +24,8 @@ func main() {

// Perhaps the most basic file reading task is
// slurping a file's entire contents into memory.
dat, err := os.ReadFile("/tmp/dat")
path := filepath.Join(os.TempDir(), "dat")
dat, err := os.ReadFile(path)
check(err)
fmt.Print(string(dat))

Expand Down
4 changes: 2 additions & 2 deletions examples/reading-files/reading-files.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
db59474ee414017c3021706ceb35d5e355f967b3
SKTzfpnV0To
444f239565d06eabfc9fa9370db205fff292b238
xKVFTA3G9k6
7 changes: 5 additions & 2 deletions examples/writing-files/writing-files.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"
)

func check(e error) {
Expand All @@ -20,11 +21,13 @@ func main() {
// To start, here's how to dump a string (or just
// bytes) into a file.
d1 := []byte("hello\ngo\n")
err := os.WriteFile("/tmp/dat1", d1, 0644)
path1 := filepath.Join(os.TempDir(), "dat1")
err := os.WriteFile(path1, d1, 0644)
check(err)

// For more granular writes, open a file for writing.
f, err := os.Create("/tmp/dat2")
path2 := filepath.Join(os.TempDir(), "dat2")
f, err := os.Create(path2)
check(err)

// It's idiomatic to defer a `Close` immediately
Expand Down
4 changes: 2 additions & 2 deletions examples/writing-files/writing-files.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
e312100df0c063ecd65e7599653636188277b6a6
Y12O-L_zFS1
b93857561df33d0ed970d15e26f321627e770655
iuKQDnKfl2T
8 changes: 5 additions & 3 deletions public/defer

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions public/reading-files

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading