Standard library / os
os.Getgroups()
Returns supplementary group IDs when supported; the order and membership are environment dependent. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Getgroups() ([]int, error)Return Value
([]int, error)
Returns supplementary group IDs when supported; the order and membership are environment dependent.
Working Example
Example Snippetgo
package main
import ( "fmt" "os")
func must(e error) { if e != nil { panic(e) }}func main() { g, e := os.Getgroups() must(e) ok := true for _, id := range g { if id < 0 { ok = false } } fmt.Println(ok)}