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.
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])
}
}
Syntax:
Consider the below example demonstrating how to get environment variables using syscall in Golang?
Output
need an explanation for this answer? contact us directly to get an explanation for this answer