home Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/home/ Fri, 17 Apr 2020 20:32:12 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 home Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/home/ 32 32 159787465 Get Current User’s Home Directory in Go (Golang) https://vikasboss.github.io/get-current-user-home-directory-go/ https://vikasboss.github.io/get-current-user-home-directory-go/#respond Fri, 17 Apr 2020 20:31:59 +0000 https://vikasboss.github.io/?p=2049 Overview ‘os/user’ package can be used to get the current user home directory Let’s see a working code Code Output

The post Get Current User’s Home Directory in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
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"

The post Get Current User’s Home Directory in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/get-current-user-home-directory-go/feed/ 0 2049