Home »
Golang »
Golang Reference
Golang os.Getgroups() Function with Examples
Golang | os.Getgroups() Function: Here, we are going to learn about the Getgroups() function of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 18, 2021
os.Getgroups()
In the Go language, the os package provides a platform-independent interface to operating system (Unix-like) functionality. The Getgroups() function is an inbuilt function of the os package, it is used to get the list of the numeric ids of groups that the caller belongs to.
It accepts nothing and returns an integer slice containing the list of the numeric ids of groups that the caller belongs to.
Note: On Windows systems, it returns syscall.EWINDOWS.
Syntax
func Getgroups() ([]int, error)
Parameters
Return Value
The return type of the os.Getgroups() function is an ([]int, error), it returns the list of the numeric ids of groups that the caller belongs to.
Example
// Golang program to demonstrate the
// example of Getgroups() function
package main
import (
"fmt"
"os"
)
func main() {
ids, err := os.Getgroups()
fmt.Printf("ids: %T, %v\n", ids, ids)
fmt.Printf("err: %T, %v\n", err, err)
}
Output:
ids: []int, [10]
err: <nil>, <nil>
Golang os Package »