Forráskód Böngészése

Merge pull request #332 from tinylcy/tinylcy-pr

use runtime to get os info
无闻 9 éve
szülő
commit
865cbc3dd3
1 módosított fájl, 3 hozzáadás és 2 törlés
  1. 3 2
      eBook/04.4.md

+ 3 - 2
eBook/04.4.md

@@ -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)