From 16f2309acbb614ce1c8c83301d6af6ca5b03fcaa Mon Sep 17 00:00:00 2001 From: yingtaojuzi <18053607+yingtaojuzi@users.noreply.github.com> Date: Thu, 13 Feb 2020 14:49:55 +0800 Subject: [PATCH] =?UTF-8?q?when=20I=20import=20the=20pack1,=20if=20I=20add?= =?UTF-8?q?=20the=20./pack1/pack1,=20it=20will=20fai=E2=80=A6=20(#760)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * when I import the pack1, if I add the ./pack1/pack1, it will failed * also the import exercise need updating * the path in this file --- eBook/09.5.md | 10 +++++----- .../book/{package_test.go => package_mytest.go} | 0 eBook/exercises/chapter_9/main_greetings.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename eBook/examples/chapter_9/book/{package_test.go => package_mytest.go} (100%) diff --git a/eBook/09.5.md b/eBook/09.5.md index b527705..741517a 100644 --- a/eBook/09.5.md +++ b/eBook/09.5.md @@ -4,7 +4,7 @@ 当写自己包的时候,要使用短小的不含有 `_`(下划线)的小写单词来为文件命名。这里有个简单例子来说明包是如何相互调用以及可见性是如何实现的。 -当前目录下(examples/chapter_9/book/)有一个名为 package_test.go 的程序, 它使用了自定义包 pack1 中 pack1.go 的代码。这段程序(连同编译链接生成的 pack1.a)存放在当前目录下一个名为 pack1 的文件夹下。所以链接器将包的对象和主程序对象链接在一起。 +当前目录下(examples/chapter_9/book/)有一个名为 package_mytest.go 的程序, 它使用了自定义包 pack1 中 pack1.go 的代码。这段程序(连同编译链接生成的 pack1.a)存放在当前目录下一个名为 pack1 的文件夹下。所以链接器将包的对象和主程序对象链接在一起。 示例 9.4 [pack1.go](examples/chapter_9/book/pack1/pack1.go): @@ -20,10 +20,10 @@ func ReturnStr() string { 它包含了一个整型变量 `Pack1Int` 和一个返回字符串的函数 `ReturnStr`。这段程序在运行时不做任何的事情,因为它不包含有一个 main 函数。 -在主程序 package_test.go 中这个包通过声明的方式被导入 +在主程序 package_mytest.go 中这个包通过声明的方式被导入, 只到包的目录一层。 ```go -import "./pack1/pack1" +import "./pack1" ``` import 的一般格式如下: @@ -36,14 +36,14 @@ import 的一般格式如下: 路径是指当前目录的相对路径。 -示例 9.5 [package_test.go](examples/chapter_9/book/package_test.go): +示例 9.5 [package_mytest.go](examples/chapter_9/book/package_mytest.go): ```go package main import ( "fmt" - "./pack1/pack1" + "./pack1" ) func main() { diff --git a/eBook/examples/chapter_9/book/package_test.go b/eBook/examples/chapter_9/book/package_mytest.go similarity index 100% rename from eBook/examples/chapter_9/book/package_test.go rename to eBook/examples/chapter_9/book/package_mytest.go diff --git a/eBook/exercises/chapter_9/main_greetings.go b/eBook/exercises/chapter_9/main_greetings.go index e9ef976..78c1170 100755 --- a/eBook/exercises/chapter_9/main_greetings.go +++ b/eBook/exercises/chapter_9/main_greetings.go @@ -1,7 +1,7 @@ package main import ( - "./greetings/greetings" + "./greetings" "fmt" )