Search code examples
filegopermissionsuserid

How to set gid and uid in os.FileMode in golang?


I want to set the uid and gid on files that are created by our golang application. It looks like the right place is use the os.FileMode. I am looking for an example of setting the permissions and uid and gid all in one step.

Setting the permissions looks pretty straightforward:

os.FileMode(hdr.Mode&0777)

But I am not sure how to also set the uid/gid on FileMode.


Solution

  • Not sure what do you mean by one step, I use following method to set uid & gid

    func Chown(path string, uid int, gid int)

    https://golang.org/pkg/syscall/#Chown