~rbn/neinp

ref: 280ca11dc4f314d4bb506de2f219eb70dd959227 neinp/id/uidgid.go -rw-r--r-- 528 bytes
280ca11dRuben Schuller update go.mod 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Package id provides utility functions to convert unix uid/gid to strings.
package id

import (
	"os/user"
	"strconv"
)

//UidToName returns the user name for an uid.
func UidToName(uid uint32) (string, error) {
	x, err := user.LookupId(strconv.Itoa(int(uid)))
	if err != nil {
		return "", err
	}
	return x.Name, nil
}

//GidToName returns the group name for an gid.
func GidToName(gid uint32) (string, error) {
	y, err := user.LookupGroupId(strconv.Itoa(int(gid)))
	if err != nil {
		return "", err
	}
	return y.Name, nil
}