谢大的教程在:https://github.com/astaxie/build-web-application-with-golang

在复刻和学习的过程中,把问题记录下来的笔记
1、
// 声明一个数组
var array = [10]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
// 声明两个slice
var aSlice, bSlice []byte

// 演示一些简便操作
aSlice = array[:3] // 等价于aSlice = array[0:3] aSlice包含元素: a,b,c
aSlice = array[5:] // 等价于aSlice = array[5:10] aSlice包含元素: f,g,h,i,j
aSlice = array[:] // 等价于aSlice = array[0:10] 这样aSlice包含了全部的元素

// 从slice中获取slice
aSlice = array[3:7] // aSlice包含元素: d,e,f,g,len=4,cap=7
bSlice = aSlice[1:3] // bSlice 包含aSlice[1], aSlice[2] 也就是含有: e,f
bSlice = aSlice[:3] // bSlice 包含 aSlice[0], aSlice[1], aSlice[2] 也就是含有: d,e,f
bSlice = aSlice[0:5] // 对slice的slice可以在cap范围内扩展,此时bSlice包含:d,e,f,g,h
bSlice = aSlice[:] // bSlice包含所有aSlice的元素: d,e,f,g
主要是加深颜色的那句。。。。
2、
type human struct {
name string
age string
height int
}
type student struct {
human
skills
int
age int
speciality string
}
func (h *human) sayhi() {
fmt.Printf("human say hello, i'm %s \n", h.name)
}
func (h *human) gogo() {
fmt.Println("gogogo");
}
type men interface{
sayhi()
gogo()
}

然后用的地方:
mike := student{human:human{name:"mike"}}
var i men;
i = mike;
i.sayhi();
因为这是早期的所见所得编辑器。对于代码高亮做的不好。忍忍吧。。。
上面的代码是会出错的。
cannot use mike (type student) as type men in assignment:
student does not implement men (gogo method requires pointer receiver)
需要:mike := &student{human:human{name:"mike"}}
看到没,在student前有个取址符。主要是因为方法指定的是:(h *human),如果是(h human),就不需要取址符了
*human 是指针,但是你mike不是指针,只是对象,所以没有实现这两个方法,才会报错
然后谢大给出了这个:http://segmentfault.com/q/1010000000198984#a-1020000000199002,说是里面有解释
假设T是struct,那么Go里面遵循下面几个原则:

T的方法集仅拥有 T Receiver 方法。
*T 方法集则包含全部方法 (T + *T)。

所以你上面的例子dept1应该是拥有方法:Name和SetName
而&dept1拥有方法:Name、SetName和Relocate
这个就是Go里面在设计方法的时候需要注意Receiver的类型