Merge pull request #332 from tinylcy/tinylcy-pr

use runtime to get os info
This commit is contained in:
无闻
2017-03-10 10:30:45 -05:00
committed by GitHub

View File

@@ -113,7 +113,7 @@ var (
a := 1
```
下面这个例子展示了如何在运行时获取所在的操作系统类型,通过 `os` 包中的函数 `os.Getenv()` 来获取环境变量中的值,并保存到 string 类型的局部变量 path 中。
下面这个例子展示了如何通过`runtime`在运行时获取所在的操作系统类型,以及如何通过 `os` 包中的函数 `os.Getenv()` 来获取环境变量中的值,并保存到 string 类型的局部变量 path 中。
示例 4.5 [goos.go](examples/chapter_4/goos.go)
@@ -122,11 +122,12 @@ package main
import (
"fmt"
"runtime"
"os"
)
func main() {
var goos string = os.Getenv("GOOS")
var goos string = runtime.GOOS
fmt.Printf("The operating system is: %s\n", goos)
path := os.Getenv("PATH")
fmt.Printf("Path is %s\n", path)