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 : ....

本文来自:博客园

感谢作者:jackkiexu

查看原文:environment variables _ golang

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。