How can I get a file's group ID (GID) in Go?

后端 未结 1 1272
忘掉有多难
忘掉有多难 2021-01-19 02:45

os.Stat() returns a FileInfo object, which has a Sys() method that returns an Interface{} with no methods.

Though I am able to

相关标签:
1条回答
  • 2021-01-19 03:08

    The reflect module showed that the data type for Sys()'s return is *syscall.Stat_t, so this seems to work to get the Gid of a file as a string:

    file_info, _ := os.Stat(abspath)
    file_sys := file_info.Sys()
    file_gid := fmt.Sprint(file_sys.(*syscall.Stat_t).Gid)
    

    Please let me know if there is a better way to do this.

    0 讨论(0)
提交回复
热议问题