一 新类型定义
类型定义 type a int 定义一个具有int类型属性的a新类型
特点
- go语言不允许为简单的内置类型添加方法,但是定义一个继承简单内置类型的新的类型,可以绑定方法
- 新的类型定义好算一个新类型,比如上述定义和int比较 是需要先进性类型转化
- type byNamePort [](*InstanceKey) 也可以定义指针类型切片
- type byNamePort int 也可以定义基本类型
type ReplicationThreadState int const ReplicationThreadState =1 //定义变量 func ReplicationThreadStateFromStatus(status string) ReplicationThreadState { //作为返回值类型 switch status { case "No": return ReplicationThreadStateStopped case "Yes": return ReplicationThreadStateRunning } return ReplicationThreadStateOther } func (this *ReplicationThreadState) IsRunning() bool { return *this == ReplicationThreadStateRunning } //新类型绑定方法