jx/internal/resource/os.go

46 lines
835 B
Go
Raw Normal View History

2024-03-20 19:23:31 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
2024-03-22 17:39:06 +00:00
//
2024-03-20 16:15:27 +00:00
package resource
import (
"os/user"
"strconv"
)
2024-03-20 19:23:31 +00:00
func LookupUIDString(userName string) string {
user, userLookupErr := user.Lookup(userName)
if userLookupErr != nil {
return ""
}
return user.Uid
}
2024-03-20 16:15:27 +00:00
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
}