摘要: 在《The Little Go Book》里有关于 channel 的一段话: In other words, a goroutine that has data can pass it to another goroutine via a channel. The result is that, 阅读全文
posted @ 2017-04-23 00:12 AHUI-2017 阅读(234) 评论(0) 推荐(0) 编辑
摘要: The Little Go Book http://openmymind.net/The-Little-Go-Book/ 里面介绍了 Embedding 的实现方法, 示例程序如下(有修改): 其中,特别需要注意的是,虽然 goku 可以“免费”获得 Person 的全部能力(比如 .Name 和 阅读全文
posted @ 2017-04-09 23:53 AHUI-2017 阅读(174) 评论(0) 推荐(0) 编辑
摘要: Every package should have a package comment, a block comment preceding the package clause. Every exported (capitalized) name in a program should have 阅读全文
posted @ 2017-04-09 21:46 AHUI-2017 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 在 Effective Go 中,介绍了一种 goroutine 与 channel 搭配使用的方法。 在这个示例中,使用 go func() {}() 相当于让一段代码在背景执行,我们不用等待它结束就可以继续执行下面的程序,因此,该程序的运行结果是最先打印 "Go after." 如果不使用 ch 阅读全文
posted @ 2017-04-03 17:43 AHUI-2017 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Effective Go 里的一个小节 Interfaces and methods (https://golang.org/doc/effective_go.html#interface_methods) 介绍了把 method 附加到 function 上的方法。 1. 首先,创建一种 type 阅读全文
posted @ 2017-03-23 20:49 AHUI-2017 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 学习了 Effective Go 中 Generality 小节的内容 https://golang.org/doc/effective_go.html#generality 由于这个小节的内容稍有点抽象,因此写了以下示例程序以便加深理解。 本程序的结果是,打印 Ver. 1 Ver. 2 阅读全文
posted @ 2017-03-22 23:13 AHUI-2017 阅读(319) 评论(0) 推荐(0) 编辑
摘要: 这是一个小示例,说明一个 value 同时可以既是这种 interface 又是那种 interface。 其中,i 不能是 non-interface type, 可以是 interface{} 或者 Ia 或者 Ib。 阅读全文
posted @ 2017-03-20 00:36 AHUI-2017 阅读(281) 评论(0) 推荐(0) 编辑
摘要: A Tour of Go concurrency >> sync.Mutex https://tour.golang.org/concurrency/9 golang 里的 map 并不是 concurrency-safe 的,也就是说,当多个 goroutine 对同一个 map 进行操作时,有可 阅读全文
posted @ 2017-02-10 16:36 AHUI-2017 阅读(1104) 评论(0) 推荐(0) 编辑
摘要: A Tour of Go Exercise: Equivalent Binary Trees https://tour.golang.org/concurrency/7 检查两棵二叉树是否包含相同的数值,这题难度稍大,有几个难点。 答案如下: 其中,函数 walk 用递归方法遍历二叉树 在 walk 阅读全文
posted @ 2017-02-09 19:19 AHUI-2017 阅读(710) 评论(0) 推荐(0) 编辑
摘要: 2017年1月29日,开始学习 golang, 一边学习一边做笔记。 ◆ Golang 的开发环境非常容易搭建,双击安装包安装后,设置一个系统变量即可。 安装 go 1.8 以上版本,则连这个系统变量也不用设置,默认 %USERPROFILE%\go 为 workspace, 因此,只要在 %USE 阅读全文
posted @ 2017-02-08 12:27 AHUI-2017 阅读(384) 评论(0) 推荐(0) 编辑