It could be beneficial for the program to know the user's home directory, for example, in case you need to store a custom user configuration or any other data related to the user. This recipe will describe how you can find out the current user's home directory.
Resolving the user home directory
How to do it...
- Open the console and create the folder chapter06/recipe10.
- Navigate to the directory.
- Create the home.go file with the following content:
package main
import (
"fmt"
"log"
"os/user"
)
func main() {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
fmt.Println("...