https://segmentfault.com/a/ package main import ( "fmt" ) type BitFlag int const ( // iota为0,1左移0位 = 1 Active BitFlag = 1 << iota // Send <=> Active <=> 1 << iota,此时iota为1,1左移1位 = 2 Send // Receive <=> Send <=> 1 << i
go模仿JAVA面向接口_链式编程
https://segmentfault.com/a/ Test.go package test func NewTest() ITestIntf { return &test{""} } type ITestIntf interface { GetName() string SetName(string) ITestIntf } type test struct { name string } func (t *test) GetName() string { return (*t).name } func (t *test) SetName(n string) ITestIntf { (*t).name =n return t } SubTest.go package test func NewSubTest() ISubTestIntf { return &subTest{NewTest(), "", 0} } type ISubTestIntf interface { ITestIntf GetSex() string SetSex(string) ISubTestIntf GetAge()
go语言reflect包使用的几个场景
https://segmentfault.com/a/ reflect包的几个使用场景: 1. 遍历结构体字段名(避免代码的硬编码) 2. 调用结构体方法(自动映射) 3. 获取结构体的tag标记的值(json/