So I'm attempting to create a CMS where each user makes their own website and it is stored in a directory named as their choosing. However when I use
os.Mkdir("/Users/anonrose/Documents/goCode/src/github.com/anonrose/GoDataStructs/tests/myWebsite", os."some permission")
the "some permission" part is what I'm having troubles with. When I attempt to access the directory once it's been created I never have the correct permission. Is there a os.FileMode
that I can use to set the permissions as read and write for anyone when I go to create the directory.
To create a single directory in Go, use the os. Mkdir() function. If you want to create a hierarchy of folders (nested directories), use os. MkdirAll() .
GOPATH is a variable that defines the root of your workspace. By default, the workspace directory is a directory that is named go within your user home directory (~/go for Linux and MacOS, %USERPROFILE%/go for Windows). GOPATH stores your code base and all the files that are necessary for your development.
os. Chdir() is used to change the current working directory to the named directory in golang. It is similar to the cd command.
If you need to set explicit permission bits not listed here then use os.FileMode
os.Mkdir("/path/to/dir", os.FileMode(0522))
The least significant 9 bits of the uint32 represent the file permissions, so 0777 would be 511 for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With