From e8f7a0c3c0ec343361c10e82439f325a417e13d2 Mon Sep 17 00:00:00 2001 From: tinylcy Date: Fri, 10 Mar 2017 16:11:08 +0800 Subject: [PATCH] use runtime to get os info --- eBook/04.4.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eBook/04.4.md b/eBook/04.4.md index 3f2a682..51776b8 100644 --- a/eBook/04.4.md +++ b/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)