包含标签 Go articles

Go实现不同goroutine之间的阻塞

Go 程序从 main 包的 main() 函数开始,在程序启动时,Go 程序就会为 main() 函数创建一个默认的 goroutine

所有 goroutinemain() 函数结束时会一同结束。 若在启用的goroutine中不使用WaitGroup的话会因为main函数已执行完,阻塞的函数与发送信号的函数会一同结束,不能真正实现阻塞的功能。

因此可以使用WaitGroup来实现阻塞的功能。

……

Continue reading

Go的继承与重写以及结构体嵌套

1. 首先声明两个基础结构体(其他语言的基类吧:))

1
2
3
4
5
6
7
type Animal struct {
	Name string
}

type Old struct {
	Age int
}

并给Animal类增加一个方法Walk()

1
2
3
func (a *Animal) Walk() {
	fmt.Println("Animal Walk")
}

2. 让People类嵌套(继承)上面的AnimalOld

这时可以有两种匿名嵌套(继承)方式

……

Continue reading

Usehugo

如何使用hugo

新建文章

1
2

hugo new posts/xxx.md

发布

1
hugo -d /target/dir
……

Continue reading