In this section, you will learn how to find the user ID of the current user, as well as the group IDs to which the current user belongs. Both the user ID and group IDs are positive integers kept in UNIX system files.
The name of the utility is ids.go, and it will be presented in two parts. The first part of the utility follows:
package main import ( "fmt" "os" "os/user" ) func main() { fmt.Println("User id:", os.Getuid())
Finding the user ID of the current user is as simple as calling the os.Getuid() function.
The second part of ids.go is as follows:
var u *user.User u, _ = user.Current() fmt.Print("Group ids: ") groupIDs, _ := u.GroupIds() for _, i := range groupIDs { fmt.Print(i, " ") } fmt.Println() }
On the other hand, finding...