How to Use os/user for System User Information

Retrieve the current system user's username, ID, and home directory using the os/user package in Go.

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)
}