一.接口定义 1.定义 interface类型可以定义一组方法,但是这些不需要实现,并且interface不能包含任何变量 package main import ( "fmt" ) type test interface{ print() } type Student struct{ name string age int score int } func (p *Student)print(){ fmt.Println("name",p.name) fmt.Pr…
今天看Martini文档,其功能列表提到完全兼容http.HandlerFunc接口,就去查阅了Go: net/http的文档,看到type HandlerFunc这部分,顿时蒙圈了.由于之前学习的时候没有关注过function types的知识点,就Google了一些文章,才算是有了个大概的了解. 从golang的官方文档得知function types的解释是这样的. A function type denotes the set of all functions with the same…
结构体: 1.用来自定义复杂数据结构 2.struct里面可以包含多个字段(属性) 3.struct类型可以定义方法,注意和函数的区分 4.strucr类型是值类型 5.struct类型可以嵌套 6.go语言中没有class类型,只有struct类型 struct声明: type 标识符 struct{ field1 type field2 type } 例子: type Student struct{ Name string Age int Score int } struct中字段访问,…