Overview
‘os/user’ package can be used to get the current user home directory
Let’s see a working code
Code
package main
import (
"fmt"
"log"
"os/user"
)
func main() {
user, err := user.Current()
if err != nil {
log.Fatalf(err.Error())
}
homeDirectory := user.HomeDir
fmt.Printf("Home Directory: %s\n", homeDirectory)
}
Output
Home Directory: "some_home_directory"