GolangNote

Golang笔记

Golang 获取环境变量

Permalink

Golang 通过标准库 os 获取环境变量

Go: 获取环境变量
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package main

import (
    "fmt"
    "os"
)

func main() {
    for _, v := range os.Environ() {
        //输出系统所有环境变量的值
        fmt.Println(v)
    }
    // 获取单个变量
    home:= os.Getenv("HOME")
    fmt.Println(home)
}

本文网址: https://golangnote.com/topic/203.html 转摘请注明来源

Related articles

Write a Comment to "Golang 获取环境变量"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.20 Processed in 0ms