package main import "os/user" func lookupGroupNames(u *user.User) ([]string, error) { groups, err := u.GroupIds() if err != nil { return nil, err } var names []string for _, v := range groups { group, err := user.LookupGroupId(v) if err != nil { return nil, err } names = append(names, group.Name) } return names, nil }