Method of getting system environment variables in GO language
- 2020-05-19 05:00:07
- OfStack
This article demonstrates an example of how the GO language gets system environment variables. Share with you for your reference. The specific implementation method is as follows:
package main
import (
"fmt"
"os" // We're going to use os In the package env
)
func main() {
//os.Getenv Retrieve the environment variable and return the value, which would be empty if the variable did not exist.
HOME:= os.Getenv("HOME")
fmt.Println(HOME)
fmt.Printf(os.Getenv("JAVA_HOME"))
}
I hope this article has been helpful to your programming of Go language.