environment variables _ golang
Environment variables are a univerial mechanism for conveying configuration information to Unix programs. Let's look at how to set, get, and list environmant variables
package main import ( "fmt" "os" "strings" ) func main() { os.Setenv("FOO", "1") fmt.Println("FOO:", os.Getenv("FOO")) fmt.Println("BAR:", os.Getenv("BAR")) for _, e := range os.Environ() { pair := strings.Split(e, "=") fmt.Println(pair[0]) } }
FOO: 1 BAR: 2 BAR TERM_PROGRAM SHELL TERM TMPDIR Apple_PubSub_Socket_Render TERM_PROGRAM_VERSION OLDPWD TERM_SESSION_ID USER SSH_AUTH_SOCK __CF_USER_TEXT_ENCODING PATH PWD XPC_FLAGS XPC_SERVICE_NAME SHLVL HOME LOGNAME LC_CTYPE GOPATH _ FOO
总结 :
1 : ....