Does anyone know how to set the environmental variable in Golang by using :
os.Getenv()
You don't use os.Getenv
to set a variable but to get a value of the
variable. Use os.Setenv
to set a variable like that:
package main
import (
"fmt"
"os"
)
func main() {
os.Setenv("VAR", "10")
fmt.Println("value of VAR:", os.Getenv("VAR"))
}
Also notice that retrieving value of an environment variable that has been set in the same program doesn't make sense - they are usually used to pass environment to child processes.