os: show how to print permission bits in octal

Permission bits are most commonly viewed in string form (rwx-- etc) or
in octal form (0755), but the latter is relatively rare in Go.
Demonstrate how to print a FileMode in readable octal format.

Change-Id: I41feb801bcecb5077d4eabafdea27c149fc179a1
Reviewed-on: https://go-review.googlesource.com/c/154423
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Kevin Burke 2018-12-17 00:37:07 +00:00 committed by Brad Fitzpatrick
parent 7ef718f16f
commit c343b6b2b8

View file

@ -55,6 +55,7 @@ func ExampleFileMode() {
log.Fatal(err)
}
fmt.Printf("permissions: %#o\n", fi.Mode().Perm()) // 0400, 0777, etc.
switch mode := fi.Mode(); {
case mode.IsRegular():
fmt.Println("regular file")