在golang中如何设置os.FileMode中的gid和uid?

huangapple go评论96阅读模式
英文:

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)

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

huangapple
  • 本文由 发表于 2017年1月23日 23:55:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/41810404.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定