I created a group on a Linux machine. Now I am trying to call os.Chown
to change a file's ownership to that new group.
os.Chown
requires me to know the uid
and the gid
:
func Chown(name string, uid, gid int) error
How can I get the gid
for my group? I tried using user.Lookup("groupname")
, but I got "unknown user groupname"
I can call os.Getgroups
, but this only returns me an array of group IDs - it doesn't tell me anything about the mapping between a group name and the group id.
I am guessing there is a Unix utility I can shell out to (parse the result of calling id
) but I'd rather not do that if I can help it.