Menu Close

Go – How to get list of the numeric ids of groups of caller in go

Here, We will learn how to get list of the numeric ids of groups of caller in go. We can do it by using Getgroups() function in os package in go golang.

Function prototype:

func Getgroups() ([]int, error)

Return value:

Getgroups() function in os package returns 
a list of the numeric ids of groups that the 
caller belongs to.

Example with code:

package main

import "fmt"
import "os"


func main() {

  ids, err := os.Getgroups()

  fmt.Println(ids, ",", err)

}

Output:

[20 12 61 79 80 81] , <nil>

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, os

Leave a Reply

Your email address will not be published. Required fields are marked *