Home »
Golang »
Golang Reference
Golang os.Getuid() Function with Examples
Golang | os.Getuid() Function: Here, we are going to learn about the Getuid() function of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 19, 2021
os.Getuid()
In the Go language, the os package provides a platform-independent interface to operating system (Unix-like) functionality. The Getuid() function is an inbuilt function of the os package, it is used to get the numeric user id of the caller.
It accepts nothing and returns an integer that is the numeric user id of the caller.
Note: On Windows systems, it returns -1.
Syntax
func Getuid() int
Parameters
Return Value
The return type of the os.Getuid() function is an int, it returns the numeric user id of the caller.
Example
// Golang program to demonstrate the
// example of Getuid() function
package main
import (
"fmt"
"os"
)
func main() {
uid := os.Getuid()
fmt.Printf("uid: %T, %v\n",
uid, uid)
}
Output:
uid: int, 14028
Golang os Package »