Reputation: 49
I want to use LookupGroupId
function in os/user
with this definition :
func LookupGroupId(gid string) (*Group, error) {
return lookupGroupId(gid)
}
and here is the lookupGroupId
definition:
func lookupGroupId(gid string) (*Group, error) {
sid, err := syscall.StringToSid(gid)
if err != nil {
return nil, err
}
groupname, _, t, err := sid.LookupAccount("")
if err != nil {
return nil, err
}
if t != syscall.SidTypeGroup && t != syscall.SidTypeWellKnownGroup && t != syscall.SidTypeAlias {
return nil, fmt.Errorf("lookupGroupId: should be group account type, not %d", t)
}
return &Group{Name: groupname, Gid: gid}, nil
}
and I want to run the lookup and then save the Name and SID in a variable which will be a var of type Group
as below:
var userGroup = user.Group{Gid: "", Name: ""}
Already tried this, but nothing happens. Its like the app wont even save it anywhere.
user.LookupGroupId("S-1-5-32-545") // Users group SID
Which part I am doing wrong? I already tried this code as well:
userGroup, _ = user.LookupGroupId("S-1-5-32-545")
But I get this error:
cannot assign *user.Group to userGroup (type user.Group) in multiple assignment
Upvotes: 1
Views: 461
Reputation: 747
The error points out that you are returing two variables but only one variable is being used to capture it.
You could try like this and see if that works
userGroup, _ := user.LookupGroupId("S-1-5-32-545")
Upvotes: 1