Golang os.Environ() and Getenv() functions examples

package os

Golang os.Environ() and Getenv() functions usage examples

Example 1:

Get all environment variables

 package main

 import (
 "fmt"
 "os"
 )

 func main() {

 env := os.Environ()

 //fmt.Println(env)

 for _, v := range env {
 fmt.Printf(" %v \n", v)
 }


 }

Example 2 :

Get one environment variable

 Home := os.Getenv("HOME")

Reference :

http://golang.org/pkg/os/#Environ

Advertisement