jx/internal/resource/os.go
2024-03-20 09:15:27 -07:00

35 lines
588 B
Go

package resource
import (
"os/user"
"strconv"
)
func LookupUID(userName string) (int,error) {
user, userLookupErr := user.Lookup(userName)
if userLookupErr != nil {
return -1,userLookupErr
}
uid, uidErr := strconv.Atoi(user.Uid)
if uidErr != nil {
return -1,uidErr
}
return uid,nil
}
func LookupGID(groupName string) (int,error) {
group, groupLookupErr := user.LookupGroup(groupName)
if groupLookupErr != nil {
return -1,groupLookupErr
}
gid, gidErr := strconv.Atoi(group.Gid)
if gidErr != nil {
return -1,gidErr
}
return gid, nil
}