第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 Go 中讀取 Linux 環(huán)境變量

如何在 Go 中讀取 Linux 環(huán)境變量

Go
動(dòng)漫人物 2022-07-11 16:29:42
我正在嘗試讀取環(huán)境變量,例如將密碼存儲(chǔ)在我的代碼之外。.bashrc嘗試在和 中設(shè)置它/etc/environment,但沒有運(yùn)氣:func Test_env(t *testing.T) {    variable, exists := os.LookupEnv("SOME_PASS_ENV")    log.Printf("%v%v", variable, exists)}=== RUN   Test_env2020/11/06 12:26:07 env_value:  exists?: false該變量在設(shè)置后全局可用/etc/environment。我還可以做些什么?謝謝。以防萬一,getEnv("SOME_PASS_ENV")什么都不返回,這就是為什么LookupEnv要檢查的原因。
查看完整描述

1 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

當(dāng)您不需要區(qū)分空的環(huán)境變量值和未設(shè)置的環(huán)境變量時(shí),使用os.Getenv獲取環(huán)境變量的值。


func Getenv(key string) string

    Getenv retrieves the value of the environment variable named by the key. It

    returns the value, which will be empty if the variable is not present. To

    distinguish between an empty value and an unset value, use LookupEnv.

當(dāng)您確實(shí)需要區(qū)分空的環(huán)境變量值和未設(shè)置的環(huán)境變量時(shí),請(qǐng)使用os.Lookupenv 。


func LookupEnv(key string) (string, bool)

    LookupEnv retrieves the value of the environment variable named by the key.

    If the variable is present in the environment the value (which may be empty)

    is returned and the boolean is true. Otherwise the returned value will be

    empty and the boolean will be false.

使用os.Environ獲取所有環(huán)境變量及其值的列表。


func Environ() []string

    Environ returns a copy of strings representing the environment, in the form

    "key=value".

旁注:也許您沒有正確設(shè)置環(huán)境變量。export SOME_PASS_ENV=some_value在運(yùn)行之前嘗試直接在 shell 中設(shè)置go test


查看完整回答
反對(duì) 回復(fù) 2022-07-11
  • 1 回答
  • 0 關(guān)注
  • 171 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)