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

Golang 实现 10 进制转 N 进制

给定一个不没有重复字符的字符串,如 `[0-9,a-z]`,把一个 10 进制数字转为,该字符集的字符串。应用场合如汽车牌、顺序计数。...

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

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