英文:
How to set gid and uid in os.FileMode in golang?
问题
我想在我们的 Golang 应用程序创建的文件上设置 uid 和 gid。看起来合适的地方是使用 os.FileMode。我正在寻找一个同时设置权限、uid 和 gid 的示例。
设置权限看起来很简单:
os.FileMode(hdr.Mode&0777)
但我不确定如何在 FileMode 上设置 uid/gid。
英文:
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.
答案1
得分: 1
不确定你所说的“一步”是什么意思,我使用以下方法来设置 uid 和 gid:
func Chown(path string, uid int, gid int)
https://golang.org/pkg/syscall/#Chown
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论