Use the os/user package to retrieve the current user's information by calling user.Current(). This function returns a *User struct containing the username, user ID, group ID, and home directory.
package main
import (
"fmt"
"os/user"
)
func main() {
u, err := user.Current()
if err != nil {
panic(err)
}
fmt.Printf("Username: %s, UID: %s, Home: %s\n", u.Username, u.Uid, u.HomeDir)
}