GO語言"os"包中"Getenv"函數的用法及代碼示例。
用法:
func Getenv(key string) string
Getenv 檢索由鍵命名的環境變量的值。它返回值,如果變量不存在,該值將為空。要區分空值和未設置值,請使用 LookupEnv
例子:
package main
import (
"fmt"
"os"
)
func main() {
os.Setenv("NAME", "gopher")
os.Setenv("BURROW", "/usr/gopher")
fmt.Printf("%s lives in %s.\n", os.Getenv("NAME"), os.Getenv("BURROW"))
}
輸出:
gopher lives in /usr/gopher.
相關用法
- GO Get用法及代碼示例
- GO GoStringer用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
- GO NewFromFiles用法及代碼示例
- GO Regexp.FindString用法及代碼示例
- GO Time.Sub用法及代碼示例
- GO Regexp.FindAllIndex用法及代碼示例
- GO Encode用法及代碼示例
- GO ResponseRecorder用法及代碼示例
- GO Value用法及代碼示例
- GO StreamWriter用法及代碼示例
- GO Fscanln用法及代碼示例
- GO Values.Get用法及代碼示例
- GO NumError用法及代碼示例
- GO TrailingZeros8用法及代碼示例
- GO Logger.Output用法及代碼示例
- GO Float.SetString用法及代碼示例
- GO NewReader用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Getenv。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。