From: Jaana Burcu Dogan Date: Mon, 29 Aug 2016 06:11:00 +0000 (-0700) Subject: os: add example for OpenFile X-Git-Tag: go1.8beta1~1594 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=428d79bd38db30405fe2b5d264d856e52030c338;p=gostls13.git os: add example for OpenFile New beginners are not familiar with open(2)-style masking of the flags. Add an example demonstrates the flag or'ing. Change-Id: Ifa8009c55173ba0dc6642c1d3b3124c766b1ebbb Reviewed-on: https://go-review.googlesource.com/27996 Reviewed-by: Brad Fitzpatrick --- diff --git a/src/os/example_test.go b/src/os/example_test.go new file mode 100644 index 0000000000..e82ee3e3c3 --- /dev/null +++ b/src/os/example_test.go @@ -0,0 +1,20 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package os_test + +import ( + "log" + "os" +) + +func ExampleOpenFile() { + f, err := os.OpenFile("notes.txt", os.O_RDWR|os.O_CREATE, 0755) + if err != nil { + log.Fatal(err) + } + if err := f.Close(); err != nil { + log.Fatal(err) + } +}