github.com/richardwilkes/toolbox@v1.121.0/xio/fs/paths/paths.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  // Package paths provides platform-specific standard paths.
    11  package paths
    12  
    13  import (
    14  	"os"
    15  	"os/user"
    16  )
    17  
    18  // HomeDir returns the home directory. If this cannot be determined for some reason, "." will be returned instead.
    19  func HomeDir() string {
    20  	if u, err := user.Current(); err == nil {
    21  		return u.HomeDir
    22  	}
    23  	if dir, err := os.UserHomeDir(); err == nil {
    24  		return dir
    25  	}
    26  	return "."
    27  }