~rbn/neinp

ref: 062a107b140085acd6c48867e4328fb3f3466a87 neinp/id/uidgid.go -rw-r--r-- 559 bytes
062a107bRuben Schuller use custom go.rbn.im import path 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 "go.rbn.im/neinp/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
}