1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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 }