go学习
coder.bihao@foxmail
这个作者很懒,什么都没留下…
展开
-
defer介绍
一.defer 介绍定义:A defer statement pushes a function call onto a list. The list of saved calls is executed after the surrounding function returns. Defer is commonly used to simplify functions that perfo...原创 2019-07-08 09:28:42 · 244 阅读 · 0 评论 -
golang协程池
package mainimport ( "fmt" "sync")type ITask interface { Execute()}type TaskForTest struct { ID int}func (t *TaskForTest) Execute() { fmt.Printf("execute task id[%d]", t...原创 2019-07-16 09:14:36 · 113 阅读 · 0 评论 -
golang总结
1.golang默认采用值传递,如果希望修改值可以通过指针、引用进行传递例如func(&arg) 注意golang中没有c++中引用参数的函数声明,需要用指针golang中的slice、map、interface、channel类型默认使用引用传递2.数组声明 可以使用 var arr2 [10]int;可以使用var arr1 = new([5]int);arr2是[5]int类型,...原创 2019-07-25 13:53:08 · 234 阅读 · 0 评论 -
golang不阻塞写协程
``golangpackage mainimport (“fmt”“time”“errors”“sync”“container/list”)type Itask interface {Execute()EchoID() int}type TestTask struct {ID int}func (t *TestTask) Execute() {fmt.Printf...原创 2019-08-01 11:18:47 · 378 阅读 · 0 评论 -
设计模式(一)
一.builder pattern一.文档https://github.com/tmrts/go-patterns/blob/master/creational/builder.mdhttps://golangvedu.wordpress.com/2017/02/09/golang-builder-pattern-creational/二.个人理解builder模式,翻译为建造模式,核心...原创 2019-08-01 15:51:52 · 117 阅读 · 0 评论 -
设计模式(二)
四.prototype pattern一.文档https://www.jianshu.com/p/42266549e6f9二.个人理解原型模式,其实是通过原型来克隆出来相同的、参数一模一样对象的一种设计模式。例如一个图片类,用户调用其画画的功能,画出了复杂的画像,此时希望对该对象进行复制使用,此时可以通过clone的方法,将此对象进行完整克隆,而不需要用户重新再画一遍。注意此时克隆出来的...原创 2019-08-01 15:52:55 · 79 阅读 · 0 评论 -
设计模式(三)
7.facade pattern一.文档https://design-patterns.readthedocs.io/zh_CN/latest/structural_patterns/facade.html二.个人理解facade模式,翻译为外观模式、门面模式,核心思想是屏蔽客户端对复杂系统的认识,通过facade将各个子系统进行整合,对外暴露简单的接口。应用场景:复杂系统的简单化三....原创 2019-08-01 15:53:36 · 149 阅读 · 0 评论 -
设计模式(四)
mediator pattern一.文档https://design-patterns.readthedocs.io/zh_CN/latest/behavioral_patterns/mediator.html二.个人理解mediator pattern模式,翻译为中介者模式。在软件开发中,项目中可能存在很多个类,而中介者模式可以避免多个类之间的直接交互,交互交给中介来做,降低了对象之间的...原创 2019-08-01 15:54:15 · 138 阅读 · 0 评论