Exemplo n.º 1
0
func valueFromUser(name string) (string, error) {
	currentUser, err := user.CurrentUser()
	if err != nil {
		return "", err
	}
	switch name {
	case "name":
		return currentUser.Name, nil
	case "uid":
		return strconv.Itoa(currentUser.Uid), nil
	case "gid":
		return strconv.Itoa(currentUser.Gid), nil
	case "home":
		return currentUser.Home, nil
	case "group":
		group, err := user.LookupGid(currentUser.Gid)
		return group.Name, err
	default:
		return "", fmt.Errorf("unknown variable \"user.%s\"", name)
	}
}
Exemplo n.º 2
0
func getUserName() (string, error) {
	currentUser, err := user.CurrentUser()
	return currentUser.Name, err
}