os.FileMode includes permission bits 0o755, 0o644, etc. (octal). Readable shorthand:
r=4, w=2, x=1.0o644: rw-r–r– (common file).0o755: rwxr-xr-x (common executable/dir traverse).f, err := os.OpenFile("out.txt", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
| Flag | Meaning |
|---|---|
O_RDONLY |
read-only |
O_WRONLY |
write-only |
O_RDWR |
read and write |
O_APPEND |
write at end |
O_CREATE |
create if missing |
O_EXCL |
error if O_CREATE and exists |
O_TRUNC |
truncate on open for write |
O_SYNC |
sync writes (platform-dependent) |
Combine with |:
os.O_CREATE | os.O_WRONLY | os.O_TRUNC
os.Mkdir / MkdirAllerr := os.MkdirAll("path/to/dir", 0o755)
Permission bits are mapped to ACLs; Go APIs still accept Unix-style modes where applicable.
fs.FileMode and typesos.ModeDir, os.ModeSymlink, etc. distinguish special file kinds in addition to permissions.