Standard library / os
os.Geteuid()
Returns effective user ID on Unix; may be -1 elsewhere. Effective identity is relevant to access checks. 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 Geteuid() intReturn Value
int
Returns effective user ID on Unix; may be -1 elsewhere.
Working Example
Example Snippetgo
package main
import ( "fmt" "os")
func must(e error) { if e != nil { panic(e) }}func main() { fmt.Println(os.Geteuid() >= 0) }