jx/internal/resource/os.go
2024-03-22 10:39:06 -07:00

46 lines
835 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
//
package resource
import (
"os/user"
"strconv"
)
func LookupUIDString(userName string) string {
user, userLookupErr := user.Lookup(userName)
if userLookupErr != nil {
return ""
}
return user.Uid
}
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
}