go - ioutil.WriteFile 文件模式/权限常量是否存储在任何地方?

标签 go

这个问题在这里已经有了答案:





How to properly instantiate os.FileMode

(2 个回答)


2年前关闭。




我关注 this简单的 go web app 教程,遇到了这个方法:

func (p *Page) save() error {
    filename := p.Title + ".txt"
    return ioutil.WriteFile(filename, p.Body, 0600)
}

关于值(value)0600它说:

The octal integer literal 0600, passed as the third parameter to WriteFile, indicates that the file should be created with read-write permissions for the current user only. (See the Unix man page open(2) for details.)



这些值是否存储在任何地方,可能在 osioutil包装为某种具有有意义名称的常量/枚举类型值?或者我们是否应该记住每个值的含义(或实现我们自己的命名常量)?

最佳答案

这些是 unix 文件系统权限的标准值。

三位数对应:

  • 业主
  • 其他(又名:所有人)

  • 各个值由以下位或一起组成:
  • 1:执行
  • 2:写
  • 4:阅读

  • 0600例如,我们有:
  • 0 : 表示八进制表示
  • 6 : write | read用户
  • 0 : 无组
  • 0 : 没有其他的

  • 更多关于 wikipedia

    关于go - ioutil.WriteFile 文件模式/权限常量是否存储在任何地方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61682796/

    相关文章:

    Golang 我怎样才能得到完整的文件路径

    go - 如果修改信号处理程序中的ctx.rip和ctx.rsp会发生什么

    Golang 中的结构文字

    arrays - 什么是 "value"数组?

    json - 如何使用Golang进行通用解码

    reflection - 通过反射传递引用嵌套结构

    docker run -w 从 go 脚本运行时出现意外错误

    sorting - 如何防止 map 排序?

    Golang profiler 找不到源代码

    go - 是否可以在模板内的结构中明智地呈现 url.URL 值?