code: func ExpandPath(path string, expand bool) (string, error) {
  	if len(path) == 0 || path[0] != '~' {
  		return path, nil
  	}
  
  	var username string
  	if slash := strings.Index(path[1:], "/"); slash > -1 {
  		username = path[1 : slash+1]
  	} else {
  		username = path[1:]
  	}
  
  	var (
  		who *user.User
  		err error
  	)
  	if len(username) == 0 {
  		who, err = currentUser()
  	} else {
  		who, err = lookupUser(username)
  	}
  
  	if err != nil {
  		return "", errors.Wrapf(err, "could not find user %s", username)
  	}
  
  	homedir := who.HomeDir
  	if expand {
  		homedir, err = filepath.EvalSymlinks(homedir)
  		if err != nil {
  			return "", errors.Wrapf(err, "cannot eval symlinks for %s", homedir)
  		}
  	}
  	return filepath.Join(homedir, path[len(username)+1:]), nil
  }
docs: // ExpandPath returns a copy of path with any references to the current user's
  // home directory (spelled "~"), or a named user's home directory (spelled
  // "~user") in the path, sanitized to the calling filesystem's path separator
  // preference.
  //
  // If the "expand" argument is given as true, the resolved path to the named
  // user's home directory will expanded with filepath.EvalSymlinks.
  //
  // If either the current or named user does not have a home directory, an error
  // will be returned.
  //
  // Otherwise, the error returned will be nil, and the string returned will be
  // the expanded path.