July 2019
Intermediate to advanced
458 pages
12h 12m
English
Another piece of information that can be handy is the current user and the groups that the process belongs to. A typical user case could be to compare them with a file-specific permission.
The os package offers the following functions:
We can see that these three functions return IDs in their numerical form:
package mainimport ( "fmt" "os")func main() { fmt.Println("User ID:", os.Getuid()) fmt.Println("Group ID:", os.Getgid()) groups, err := os.Getgroups() if err != nil { fmt.Println(err) return } fmt.Println("Group IDs:", groups)}
The full example ...
Read now
Unlock full access