参考链接 https://blog.csdn.net/tzs919/article/details/53571632 type是golang中非常重要的关键字,常见的就是定义结构体,但是其功能远不止是像c中那样只定义结构体,在golang中type关键字的功能可以说是非常丰富,通过参考相关的文章和源码,总结如下: 1 定义结构体 type person struct { name string //注意后面不能有逗号 age int } 2 类型定义,相当于定义一个别名 type name st…
标识符 字母或下划线开头 之后只能出现数字.字母.下划线 大小写敏感 Go语言关键字 break default func interface select case defer go map struct chan else goto package switch const fallthrough if range type continue for import return var 此外,还有大约30多个预定义的名字,比如int和true等,主要对应内建的常量.类型和函数 内建常量: t…
(1) 全局变量与局部变量 首先,得了解go代码块,也就是"{}",代码块外面访问不到代码块里面的变量. 在go语言里,变量民首写字母为大写则是全局变量,首写字母小写则是局部变量. 例如, package main import "fmt" // 这两个变量只能在该.go文件下访问 var a, b = 10, 20 // 这两个其他.go文件都可以访问 var A, B = 10, 20 // 全局变量范围>局部变量范围 // 代码块里面的变量只能在代码块里…
map[string]interface{} is not the same as map[string]string. Type interface{} is not the same as type string. If they are both map[string]string: package main import "fmt" func main() { v := map[string]string{"hello": "world"…