X
X
xotkot2018-02-22 01:31:01
linux
xotkot, 2018-02-22 01:31:01

How can I find out the name of the owner of a file?

How to find out the name of the owner of the desired file using golang?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2018-02-22
@xotkot

import (
    "fmt"
    "os"
    "os/user"
    "syscall"
)
func fileUserName(filename string) (username string, err error) {
  stat, err := os.Stat(filename)
  if os.IsNotExist(err) {
    return
  }
  uid := stat.Sys().(*syscall.Stat_t).Uid
  User, _ := user.LookupId(fmt.Sprint(uid))
  username = User.Username
  return
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question