aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Burke <kev@inburke.com>2017-02-28 16:28:34 -0800
committerIan Lance Taylor <iant@golang.org>2017-03-01 14:48:21 +0000
commit6d32b1a3431dba378d22fa8b187ccfeab259cbe2 (patch)
tree0ad73f615ec86efb60b8b844aee98181cbe7b94e /src
parent9bd1cc3fa1145182e9ce041d0e96bd2051cd7fcf (diff)
downloadgo-6d32b1a3431dba378d22fa8b187ccfeab259cbe2.tar.xz
os: add OpenFile example for appending data
Fixes #19329. Change-Id: I6d8bb112a56d751a6d3ea9bd6021803cb9f59234 Reviewed-on: https://go-review.googlesource.com/37619 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/os/example_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/os/example_test.go b/src/os/example_test.go
index 07f9c76959..d10bab4e1b 100644
--- a/src/os/example_test.go
+++ b/src/os/example_test.go
@@ -21,6 +21,20 @@ func ExampleOpenFile() {
}
}
+func ExampleOpenFile_append() {
+ // If the file doesn't exist, create it, or append to the file
+ f, err := os.OpenFile("access.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if _, err := f.Write([]byte("appended some data\n")); err != nil {
+ log.Fatal(err)
+ }
+ if err := f.Close(); err != nil {
+ log.Fatal(err)
+ }
+}
+
func ExampleChmod() {
if err := os.Chmod("some-filename", 0644); err != nil {
log.Fatal(err)