GoCN 每日新闻 (2020-05-05)

Goroutine 的创建与销毁 :https://www.jianshu.com/p/181dc7845bb8

Golang Context 原理与实战 :https://segmentfault.com/a/1190000022534841

Go 语言 sync 包的应用详解 :https://segmentfault.com/a/1190000022545889

Go:defer 语句如何工作 :https://medium.com/a-journey-with-go/go-how-does-defer-statement-work-1a9492689b6e

Go:通过 GODEBUG 提升对协程的利用 :https://medium.com/a-journey-with-go/go-improve-the-usage-of-your-goroutines-with-godebug-4d1f33970c33

GoCN 每日新闻 (2020-05-04)

记一次对 dubbo-go-hessian2 的性能优化 :https://gocn.vip/topics/10339

只需四步,后台化你的程序 :https://ieftimov.com/post/four-steps-daemonize-your-golang-programs/

使用 kubebuilder 快速搭建 k8s operator :https://medium.com/@arbaazkhan083/building-kubernetes-operator-using-kubebuilder-bb52fbd8238

用 Go+React 实现游戏 Codenames :https://github.com/rodohanna/OpenCodenames

chippy: 一款 Chip-8 模拟器 :https://github.com/bradford-hamilton/chippy

golang-闭包函数使用

主要包含四种方法

第一种

f1 := func() { //匿名函数,无参无返回值
//引用到函数外的变量
fmt.Printf(“方式1:i = %d, str = %s\n”, i, str)
}
f1() //函数调用
//方式1的另一种方式
type FuncType func() //声明函数类型, 无参无返回值
var f2 FuncType = f1
f2() //函数调用

第二种

var f3 FuncType = func() {
fmt.Printf(“方式2:i = %d, str = %s\n”, i, str)
}
f3() //函数调用

第三种

func() { //匿名函数,无参无返回值
fmt.Printf(“方式3:i = %d, str = %s\n”, i, str)
}() //别忘了后面的(), ()的作用是,此处直接调用此匿名函数

第四种

//方式4, 匿名函数,有参有返回值
v := func(a, b int) (result int) {
result = a + b
return
}(1, 1) //别忘了后面的(1, 1), (1, 1)的作用是,此处直接调用此匿名函数, 并传参
fmt.Println(“v = “, v)

把本地现有代码推至github新项目

首先 git init 把自己的代码创建为新的git项目

然后 git remote add origin git@github.com:xxxxxxx/xxxxxx.git 把本地的远程仓库设置为git中你项目的地址

之后 git add .

git commit

git push –set-upstream origin master 设置默认推送的分支

以后再推就可以用

git push origin master