Commit c343b6b2 authored by Kevin Burke's avatar Kevin Burke Committed by Brad Fitzpatrick

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: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 7ef718f1
...@@ -55,6 +55,7 @@ func ExampleFileMode() { ...@@ -55,6 +55,7 @@ func ExampleFileMode() {
log.Fatal(err) log.Fatal(err)
} }
fmt.Printf("permissions: %#o\n", fi.Mode().Perm()) // 0400, 0777, etc.
switch mode := fi.Mode(); { switch mode := fi.Mode(); {
case mode.IsRegular(): case mode.IsRegular():
fmt.Println("regular file") fmt.Println("regular file")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment