Q:

How to get the environment variables using syscall in Golang?

belongs to collection: Golang syscall Package Programs

0

In the Go programming language, to get environment variables using syscall – we use the Environ() function of the the syscall package. The Environ() function returns an array of strings populated with your environment variables.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Syntax:

func Environ() []string

Consider the below example demonstrating how to get environment variables using syscall in Golang?

package main

import (
	"fmt"
	"syscall"
)

func main() {
	// Using the Environ() function
	// Getting the environment variables
	env := syscall.Environ()

	// Printing
	fmt.Println("Environment variables:")
	for i := range env {
		fmt.Println(env[i])
	}
}

Output

Environment variables:
LANGUAGE=en_US:en
HOSTNAME=Check
HOME=/
GOROOT=/usr/local/go
TERM=xterm
PATH=/opt/swift/swift-5.0-RELEASE-ubuntu14.04/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DISPLAY=:1
LANG=en_US.UTF-8
DEBIAN_FRONTEND=noninteractive
GOCACHE=/home/.cache
LC_ALL=en_US.UTF-8
PWD=/home

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

How to get the group process identification using ... >>
<< How to get the disk usage information in Golang?...