From 10ad0b5042dbd6b9850342ab1b702eb7a1a8d27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=82=B3=E6=98=8E?= Date: Mon, 30 Mar 2020 10:02:16 +0800 Subject: [PATCH] =?UTF-8?q?Add=EF=BC=9A=E6=96=B0=E5=A2=9E=E6=96=87?= =?UTF-8?q?=E7=AB=A0<=E7=B1=BB=E5=9E=8B=E6=96=AD=E8=A8=80>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- md2rst.py | 6 +- source/c01/c01_01.rst | 3 +- source/c01/c01_02.rst | 1 - source/c01/c01_03.rst | 1 - source/c01/c01_04.rst | 1 - source/c01/c01_05.rst | 1 - source/c01/c01_06.rst | 1 - source/c01/c01_07.rst | 1 - source/c01/c01_08.rst | 1 - source/c01/c01_09.rst | 1 - source/c01/c01_10.rst | 1 - source/c01/c01_11.rst | 1 - source/c01/c01_12.rst | 1 - source/c01/c01_13.rst | 1 - source/c01/c01_14.md | 190 +++++++++++++++++++++++++++++++++++++- source/c01/c01_14.rst | 207 ++++++++++++++++++++++++++++++++++++++++-- source/c02/c02_01.rst | 1 - source/c02/c02_02.md | 2 +- source/c02/c02_02.rst | 1 - source/c02/c02_03.rst | 1 - source/c02/c02_04.rst | 1 - source/c03/c03_01.rst | 1 - source/c03/c03_02.rst | 1 - source/c03/c03_03.rst | 1 - source/c03/c03_04.rst | 1 - source/c03/c03_05.rst | 1 - source/c04/c04_01.rst | 1 - source/c04/c04_02.rst | 1 - source/c04/c04_03.rst | 3 +- source/c04/c04_04.rst | 1 - source/c04/c04_05.rst | 1 - source/c04/c04_06.rst | 1 - source/c04/c04_08.rst | 1 - source/c05/c05_01.rst | 1 - 35 files changed, 393 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 39b2402..4268134 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ - 1.11 [流程控制:goto 无条件跳转](http://golang.iswbm.com/en/latest/c01/c01_11.html) - 1.12 [流程控制:defer 延迟语句](http://golang.iswbm.com/en/latest/c01/c01_12.html) - 1.13 [异常机制:panic 和 recover](http://golang.iswbm.com/en/latest/c01/c01_13.html) -- 1.14 [Type Assertion 与 Type Switch](http://golang.iswbm.com/en/latest/c01/c01_14.html) +- 1.14 [Go 语言中的类型断言?](http://golang.iswbm.com/en/latest/c01/c01_14.html) - 1.15 [信道里使用 select](http://golang.iswbm.com/en/latest/c01/c01_15.html) ## 第二章:面向对象 diff --git a/md2rst.py b/md2rst.py index 764e47a..e8ff362 100644 --- a/md2rst.py +++ b/md2rst.py @@ -10,9 +10,9 @@ from git import Repo osName = platform.system() repo_path ='.' if (osName == 'Windows'): - repo_path = 'E:\\MING-Git\\07. GolangCodingTime' - blog_path = 'E:\\MING-Git\\07. GolangCodingTime\\source' - index_path = 'E:\\MING-Git\\07. GolangCodingTime\\README.md' + repo_path = 'E:\\MING-Git\\GolangCodingTime' + blog_path = 'E:\\MING-Git\GolangCodingTime\\source' + index_path = 'E:\\MING-Git\\GolangCodingTime\\README.md' elif (osName == 'Darwin'): repo_path = '/Users/MING/Github/GolangCodingTime/' blog_path = '/Users/MING/Github/GolangCodingTime/source' diff --git a/source/c01/c01_01.rst b/source/c01/c01_01.rst index 8ea2394..bda2bc9 100644 --- a/source/c01/c01_01.rst +++ b/source/c01/c01_01.rst @@ -57,7 +57,7 @@ Goland 下载地址:https://download.jetbrains.com/go/goland-2019.2.3.exe - 激活码.txt:激活码 将 jetbrains-agent.jar 拷贝到 你的 Goland -安装目录的bin文件夹下,我的路径是:E::raw-latex:`\Program `Files:raw-latex:`\JetBrains`:raw-latex:`\GoLand `2019.2.3:raw-latex:`\bin` +安装目录的bin文件夹下,我的路径是:E::raw-latex:`\Program `Files:raw-latex:`\JetBrains`:raw-latex:`\GoLand 2019.2`.3:raw-latex:`\bin` 然后用编辑器打开这两个文件 @@ -314,4 +314,3 @@ Code,其记录的GOPATH始终指向%USERPROFILE%:raw-latex:`\go`), .. |image24| image:: http://image.python-online.cn/20200109214117.png .. |image25| image:: http://image.python-online.cn/20200109154657.png .. |image26| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_02.rst b/source/c01/c01_02.rst index 6c98bc9..8dd0be6 100644 --- a/source/c01/c01_02.rst +++ b/source/c01/c01_02.rst @@ -207,4 +207,3 @@ float64,但是很多情况下,我们并不需要这么高的精度(占用 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_03.rst b/source/c01/c01_03.rst index 004a725..06dd6b1 100644 --- a/source/c01/c01_03.rst +++ b/source/c01/c01_03.rst @@ -233,4 +233,3 @@ https://www.zhihu.com/question/26022206 .. |image0| image:: http://image.python-online.cn/20200120204329.png .. |image1| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_04.rst b/source/c01/c01_04.rst index 8405a70..319b9f2 100644 --- a/source/c01/c01_04.rst +++ b/source/c01/c01_04.rst @@ -243,4 +243,3 @@ byte数组 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_05.rst b/source/c01/c01_05.rst index 5c16c7d..2aeaec1 100644 --- a/source/c01/c01_05.rst +++ b/source/c01/c01_05.rst @@ -232,4 +232,3 @@ |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_06.rst b/source/c01/c01_06.rst index e7331bf..ee013e2 100644 --- a/source/c01/c01_06.rst +++ b/source/c01/c01_06.rst @@ -292,4 +292,3 @@ Go 中确实不如 Python 那样灵活,bool 与 int .. |image0| image:: http://image.python-online.cn/20200106201856.png .. |image1| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_07.rst b/source/c01/c01_07.rst index 475ec96..43a0ea7 100644 --- a/source/c01/c01_07.rst +++ b/source/c01/c01_07.rst @@ -220,4 +220,3 @@ ptr(pointer的简写),而这个变量,我们称之为指针变量。 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_08.rst b/source/c01/c01_08.rst index 3a207cb..c00b575 100644 --- a/source/c01/c01_08.rst +++ b/source/c01/c01_08.rst @@ -126,4 +126,3 @@ if - else if - else |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_09.rst b/source/c01/c01_09.rst index 9c56188..34f0e7e 100644 --- a/source/c01/c01_09.rst +++ b/source/c01/c01_09.rst @@ -258,4 +258,3 @@ default 的代码块。 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_10.rst b/source/c01/c01_10.rst index 8afd093..37ca30d 100644 --- a/source/c01/c01_10.rst +++ b/source/c01/c01_10.rst @@ -174,4 +174,3 @@ range 后可接数组、切片,字符串等 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_11.rst b/source/c01/c01_11.rst index 6c5982f..1b85214 100644 --- a/source/c01/c01_11.rst +++ b/source/c01/c01_11.rst @@ -176,4 +176,3 @@ goto语句与标签之间不能有变量声明,否则编译错误。 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_12.rst b/source/c01/c01_12.rst index e6f06da..20ced6b 100644 --- a/source/c01/c01_12.rst +++ b/source/c01/c01_12.rst @@ -238,4 +238,3 @@ return 那里执行不就好了。 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_13.rst b/source/c01/c01_13.rst index 05a7627..ab4db79 100644 --- a/source/c01/c01_13.rst +++ b/source/c01/c01_13.rst @@ -151,4 +151,3 @@ recover,并不能任意使用,它有强制要求,必须得在 defer 下才 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c01/c01_14.md b/source/c01/c01_14.md index 29bcac2..be30334 100644 --- a/source/c01/c01_14.md +++ b/source/c01/c01_14.md @@ -1,11 +1,191 @@ -# 1.14 Type Assertion 与 Type Switch +# 1.14 Go 语言中的类型断言? +## Type Assertion +Type Assertion(中文名叫:类型断言),通过它可以做到以下几件事情 -https://sanyuesha.com/2017/12/01/go-interface-4/ +1. 检查 `i` 是否为 nil +2. 检查 `i` 存储的值是否为某个类型 -https://maiyang.me/post/2018-08-30-type-assertion-switch/ +具体的使用方式有两种: -https://www.kancloud.cn/hartnett/gopl-zh/126063 +**第一种:** -https://segmentfault.com/a/1190000016230264 \ No newline at end of file +``` +t := i.(T) +``` + +这个表达式可以断言一个接口对象(i)里不是 nil,并且接口对象(i)存储的值的类型是 T,如果断言成功,就会返回值给 t,如果断言失败,就会触发 panic。 + +来写段代码试验一下 + +```go +package main + +import "fmt" + +func main() { + var i interface{} = 10 + t1 := i.(int) + fmt.Println(t1) + + fmt.Println("=====分隔线=====") + + t2 := i.(string) + fmt.Println(t2) +} +``` + +运行后输出如下,可以发现在执行第二次断言的时候失败了,并且触发了 panic + +``` +10 +=====分隔线===== +panic: interface conversion: interface {} is int, not string + +goroutine 1 [running]: +main.main() + E:/GoPlayer/src/main.go:12 +0x10e +exit status 2 +``` + +如果要断言的接口值是 nil,那我们来看看也是不是也如预期一样会触发panic + +```go +package main + +func main() { + var i interface{} // nil + var _ = i.(interface{}) +} +``` + +输出如下,确实是会 触发 panic + +``` +panic: interface conversion: interface is nil, not interface {} + +goroutine 1 [running]: +main.main() + E:/GoPlayer/src/main.go:5 +0x34 +exit status 2 +``` + + + +**第二种** + +``` +t, ok:= i.(T) +``` + +和上面一样,这个表达式也是可以断言一个接口对象(i)里不是 nil,并且接口对象(i)存储的值的类型是 T,如果断言成功,就会返回其类型给 t,并且此时 ok 的值 为 true,表示断言成功。 + +如果接口值的类型,并不是我们所断言的 T,就会断言失败,但和第一种表达式不同的事,这个不会触发 panic,而是将 ok 的值设为 false ,表示断言失败,此时t 为 T 的零值。 + +稍微修改下上面的例子,如下 + +```go +package main + +import "fmt" + +func main() { + var i interface{} = 10 + t1, ok := i.(int) + fmt.Printf("%d-%t\n", t1, ok) + + fmt.Println("=====分隔线1=====") + + t2, ok := i.(string) + fmt.Printf("%s-%t\n", t2, ok) + + fmt.Println("=====分隔线2=====") + + var k interface{} // nil + t3, ok := k.(interface{}) + fmt.Println(t3, "-", ok) + + fmt.Println("=====分隔线3=====") + k = 10 + t4, ok := k.(interface{}) + fmt.Printf("%d-%t\n", t4, ok) + + t5, ok := k.(int) + fmt.Printf("%d-%t\n", t5, ok) +} +``` + +运行后输出如下,可以发现在执行第二次断言的时候,虽然失败了,但并没有触发了 panic。 + +``` +10-true +=====分隔线1===== +-false +=====分隔线2===== + - false +=====分隔线3===== +10-true +10-true +``` + +上面这段输出,你要注意的是第二个断言的输出在`-false` 之前并不是有没有输出任何 t2 的值,而是由于断言失败,所以 t2 得到的是 string 的零值也是 `""` ,它是零长度的,所以你看不到其输出。 + +## Type Switch + + + +如果需要区分多种类型,可以使用 type switch 断言,这个将会比一个一个进行类型断言更简单、直接、高效。 + +```go +package main + +import "fmt" + +func findType(i interface{}) { + switch x := i.(type) { + case int: + fmt.Println(x, "is int") + case string: + fmt.Println(x, "is string") + case nil: + fmt.Println(x, "is nil") + default: + fmt.Println(x, "not type matched") + } +} + +func main() { + findType(10) // int + findType("hello") // string + + var k interface{} // nil + findType(k) + + findType(10.23) //float64 +} + +``` + +输出如下 + +``` +10 is int +hello is string + is nil +10.23 not type matched +``` + +额外说明一下: + +- 如果你的值是 nil,那么匹配的是 `case nil` +- 如果你的值在 switch-case 里并没有匹配对应的类型,那么走的是 default 分支 + +## 参考文章 + +- [Explain Type Assertions in Go](https://stackoverflow.com/questions/38816843/explain-type-assertions-in-go) +- [Go interface 详解 (四) :类型断言](https://sanyuesha.com/2017/12/01/go-interface-4/) + +--- + +![](http://image.python-online.cn/image-20200320125724880.png) \ No newline at end of file diff --git a/source/c01/c01_14.rst b/source/c01/c01_14.rst index 133d48c..23e69c5 100644 --- a/source/c01/c01_14.rst +++ b/source/c01/c01_14.rst @@ -1,10 +1,205 @@ -1.14 Type Assertion 与 Type Switch -================================== +1.14 Go 语言中的类型断言? +========================== -https://sanyuesha.com/2017/12/01/go-interface-4/ +Type Assertion +-------------- -https://maiyang.me/post/2018-08-30-type-assertion-switch/ +Type Assertion(中文名叫:类型断言),通过它可以做到以下几件事情 -https://www.kancloud.cn/hartnett/gopl-zh/126063 +1. 检查 ``i`` 是否为 nil +2. 检查 ``i`` 存储的值是否为某个类型 -https://segmentfault.com/a/1190000016230264 +具体的使用方式有两种: + +**第一种:** + +:: + + t := i.(T) + +这个表达式可以断言一个接口对象(i)里不是 +nil,并且接口对象(i)存储的值的类型是 T,如果断言成功,就会返回值给 +t,如果断言失败,就会触发 panic。 + +来写段代码试验一下 + +.. code:: go + + package main + + import "fmt" + + func main() { + var i interface{} = 10 + t1 := i.(int) + fmt.Println(t1) + + fmt.Println("=====分隔线=====") + + t2 := i.(string) + fmt.Println(t2) + } + +运行后输出如下,可以发现在执行第二次断言的时候失败了,并且触发了 panic + +:: + + 10 + =====分隔线===== + panic: interface conversion: interface {} is int, not string + + goroutine 1 [running]: + main.main() + E:/GoPlayer/src/main.go:12 +0x10e + exit status 2 + +如果要断言的接口值是 nil,那我们来看看也是不是也如预期一样会触发panic + +.. code:: go + + package main + + func main() { + var i interface{} // nil + var _ = i.(interface{}) + } + +输出如下,确实是会 触发 panic + +:: + + panic: interface conversion: interface is nil, not interface {} + + goroutine 1 [running]: + main.main() + E:/GoPlayer/src/main.go:5 +0x34 + exit status 2 + +**第二种** + +:: + + t, ok:= i.(T) + +和上面一样,这个表达式也是可以断言一个接口对象(i)里不是 +nil,并且接口对象(i)存储的值的类型是 T,如果断言成功,就会返回其类型给 +t,并且此时 ok 的值 为 true,表示断言成功。 + +如果接口值的类型,并不是我们所断言的 +T,就会断言失败,但和第一种表达式不同的事,这个不会触发 panic,而是将 ok +的值设为 false ,表示断言失败,此时t 为 T 的零值。 + +稍微修改下上面的例子,如下 + +.. code:: go + + package main + + import "fmt" + + func main() { + var i interface{} = 10 + t1, ok := i.(int) + fmt.Printf("%d-%t\n", t1, ok) + + fmt.Println("=====分隔线1=====") + + t2, ok := i.(string) + fmt.Printf("%s-%t\n", t2, ok) + + fmt.Println("=====分隔线2=====") + + var k interface{} // nil + t3, ok := k.(interface{}) + fmt.Println(t3, "-", ok) + + fmt.Println("=====分隔线3=====") + k = 10 + t4, ok := k.(interface{}) + fmt.Printf("%d-%t\n", t4, ok) + + t5, ok := k.(int) + fmt.Printf("%d-%t\n", t5, ok) + } + +运行后输出如下,可以发现在执行第二次断言的时候,虽然失败了,但并没有触发了 +panic。 + +:: + + 10-true + =====分隔线1===== + -false + =====分隔线2===== + - false + =====分隔线3===== + 10-true + 10-true + +上面这段输出,你要注意的是第二个断言的输出在\ ``-false`` +之前并不是有没有输出任何 t2 的值,而是由于断言失败,所以 t2 得到的是 +string 的零值也是 ``""`` ,它是零长度的,所以你看不到其输出。 + +Type Switch +----------- + +如果需要区分多种类型,可以使用 type switch +断言,这个将会比一个一个进行类型断言更简单、直接、高效。 + +.. code:: go + + package main + + import "fmt" + + func findType(i interface{}) { + switch x := i.(type) { + case int: + fmt.Println(x, "is int") + case string: + fmt.Println(x, "is string") + case nil: + fmt.Println(x, "is nil") + default: + fmt.Println(x, "not type matched") + } + } + + func main() { + findType(10) // int + findType("hello") // string + + var k interface{} // nil + findType(k) + + findType(10.23) //float64 + } + +输出如下 + +:: + + 10 is int + hello is string + is nil + 10.23 not type matched + +额外说明一下: + +- 如果你的值是 nil,那么匹配的是 ``case nil`` +- 如果你的值在 switch-case 里并没有匹配对应的类型,那么走的是 default + 分支 + +参考文章 +-------- + +- `Explain Type Assertions in + Go `__ +- `Go interface 详解 (四) + :类型断言 `__ + +-------------- + +|image0| + +.. |image0| image:: http://image.python-online.cn/image-20200320125724880.png diff --git a/source/c02/c02_01.rst b/source/c02/c02_01.rst index 2ef17b5..cb89abc 100644 --- a/source/c02/c02_01.rst +++ b/source/c02/c02_01.rst @@ -268,4 +268,3 @@ staff 中,做为 staff 的一个匿名字段,staff 就直接拥有了 compan |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c02/c02_02.md b/source/c02/c02_02.md index 5f37825..054d3d6 100644 --- a/source/c02/c02_02.md +++ b/source/c02/c02_02.md @@ -28,7 +28,7 @@ type Phone interface { 这个接口的实现是隐式的,不像 JAVA 中要用 implements 显示说明。 -继续上面电话的例子,我们先定义一个 Nokia 的结构体,而它实现了 call 的方法,所以它也是一台电话。 +继续上面电话的例子,我们先定义一个 Nokia 的结构体,而它实现了 call 的方法,所以它也是一台电话。 ```go type Nokia struct { diff --git a/source/c02/c02_02.rst b/source/c02/c02_02.rst index e554f6f..fcc58e8 100644 --- a/source/c02/c02_02.rst +++ b/source/c02/c02_02.rst @@ -242,4 +242,3 @@ typing)的定义是,只要你长得像鸭子,叫起来也像鸭子,那 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c02/c02_03.rst b/source/c02/c02_03.rst index 75f99cd..434e66d 100644 --- a/source/c02/c02_03.rst +++ b/source/c02/c02_03.rst @@ -101,4 +101,3 @@ make:只能为 slice,map,chan 分配内存,并初始化,返回的是 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c02/c02_04.rst b/source/c02/c02_04.rst index 8a57997..7ef460b 100644 --- a/source/c02/c02_04.rst +++ b/source/c02/c02_04.rst @@ -158,4 +158,3 @@ name |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c03/c03_01.rst b/source/c03/c03_01.rst index de0bf79..88a26cd 100644 --- a/source/c03/c03_01.rst +++ b/source/c03/c03_01.rst @@ -323,4 +323,3 @@ go vender 械管理,除此之外,任何 Gopher 应该从此刻就投入 go m .. |image11| image:: http://image.python-online.cn/image-20200314005924877.png .. |image12| image:: http://image.python-online.cn/image-20200314005217447.png .. |image13| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c03/c03_02.rst b/source/c03/c03_02.rst index 37102bb..cf00f50 100644 --- a/source/c03/c03_02.rst +++ b/source/c03/c03_02.rst @@ -182,4 +182,3 @@ MyBlog的入口应当为 myblog.go |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c03/c03_03.rst b/source/c03/c03_03.rst index 17d56b8..f2ee465 100644 --- a/source/c03/c03_03.rst +++ b/source/c03/c03_03.rst @@ -253,4 +253,3 @@ https://juejin.im/post/5d0b865c6fb9a07f050a6f45 .. |image10| image:: http://image.python-online.cn/image-20200312221011685.png .. |image11| image:: http://image.python-online.cn/image-20200312221141028.png .. |image12| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c03/c03_04.rst b/source/c03/c03_04.rst index 67c1267..3750db9 100644 --- a/source/c03/c03_04.rst +++ b/source/c03/c03_04.rst @@ -277,4 +277,3 @@ pkg,由于这个包是我随便指定的,当然会找不到,找不到就 .. |image5| image:: http://image.python-online.cn/image-20200319222834534.png .. |image6| image:: http://image.python-online.cn/image-20200319225219195.png .. |image7| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c03/c03_05.rst b/source/c03/c03_05.rst index 7077f42..fe3e756 100644 --- a/source/c03/c03_05.rst +++ b/source/c03/c03_05.rst @@ -150,4 +150,3 @@ release 发布一个版本 .. |image8| image:: http://image.python-online.cn/image-20200321132052173.png .. |image9| image:: http://image.python-online.cn/image-20200321133247067.png .. |image10| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c04/c04_01.rst b/source/c04/c04_01.rst index 66d7c2d..c88ced6 100644 --- a/source/c04/c04_01.rst +++ b/source/c04/c04_01.rst @@ -270,4 +270,3 @@ Go语言中的函数,在你定义的时候,就规定了此函数 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c04/c04_02.rst b/source/c04/c04_02.rst index cc2cb5f..9340d6d 100644 --- a/source/c04/c04_02.rst +++ b/source/c04/c04_02.rst @@ -146,4 +146,3 @@ main 的地位相当于主线程,当 main |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c04/c04_03.rst b/source/c04/c04_03.rst index 2af75bf..7c82afa 100644 --- a/source/c04/c04_03.rst +++ b/source/c04/c04_03.rst @@ -206,7 +206,7 @@ int 等等) type Sender = chan<- int sender := make(Sender) -代码是没问题,但是你要明白信道的意义是什么?(\ **以下是我个人见解** +代码是没问题,但是你要明白信道的意义是什么?(**以下是我个人见解** 信道本身就是为了传输数据而存在的,如果只有接收者或者只有发送者,那信道就变成了只入不出或者只出不入了吗,没什么用。所以只读信道和只写信道,唇亡齿寒,缺一不可。 @@ -332,4 +332,3 @@ range关键字,在range时,要确保信道是处于关闭状态,否则循 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c04/c04_04.rst b/source/c04/c04_04.rst index 94ea508..143fe3e 100644 --- a/source/c04/c04_04.rst +++ b/source/c04/c04_04.rst @@ -179,4 +179,3 @@ range 信道已经关闭,无需等待就行。 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c04/c04_05.rst b/source/c04/c04_05.rst index fe201da..777cfb4 100644 --- a/source/c04/c04_05.rst +++ b/source/c04/c04_05.rst @@ -117,4 +117,3 @@ sync.WaitGroup。。 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c04/c04_06.rst b/source/c04/c04_06.rst index 6d9d23b..1fff5d9 100644 --- a/source/c04/c04_06.rst +++ b/source/c04/c04_06.rst @@ -232,4 +232,3 @@ defer。 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c04/c04_08.rst b/source/c04/c04_08.rst index 4be4818..7b3c91d 100644 --- a/source/c04/c04_08.rst +++ b/source/c04/c04_08.rst @@ -187,4 +187,3 @@ https://studygolang.com/articles/13344 |image0| .. |image0| image:: http://image.python-online.cn/image-20200320125724880.png - diff --git a/source/c05/c05_01.rst b/source/c05/c05_01.rst index c987b49..3958415 100644 --- a/source/c05/c05_01.rst +++ b/source/c05/c05_01.rst @@ -209,4 +209,3 @@ .. |image0| image:: /Users/MING/Library/Application%20Support/typora-user-images/image-20200324211928616.png .. |image1| image:: /Users/MING/Library/Application%20Support/typora-user-images/image-20200324205302201.png - -- GitLab