September 2017
Intermediate to advanced
466 pages
9h 33m
English
Each user can belong to more than one group: this section will show how to find out the list of groups a user belongs to, given their username.
The name of the utility will be listGroups.go, and it will be presented in four parts. The first part of listGroups.go is the following:
package main import ( "fmt" "os" "os/user" )
The second part has the following Go code:
func main() {
arguments := os.Args
var u *user.User
var err error
if len(arguments) == 1 {
u, err = user.Current()
if err != nil {
fmt.Println(err)
return
}
The approach that listGroups.go takes when there are no command-line arguments is similar to the one found in userID.go. However, there is a big difference, as this time you do not ...
Read now
Unlock full access