Get the currently logged in user in golang

Viewed 61

user.Current() returns user running the current application, which in most cases is NT AUTHORITY\SYSTEM on Win 10. It does NOT return the currently logged in user.

user, err := user.Current()
if err != nil {
    log.Fatalf(err.Error())
}

username := user.Username

fmt.Printf("Username: %s\n", username)

How to get the currently logged in user in golang?

0 Answers
Related