go map高级用法链式调用
作者:互联网
正常map的使用
var map1 = make(map[string]interface{})
map1["Name"] = "lisi"
fmt.Println(map1)
链式调用方式
type TestMap map[string]interface{} func NewTestMap() TestMap { return make(map[string]interface{}) } func (this TestMap) withPar(k string, v interface{}) TestMap { this[k] = v return this } func main(){ testmap := NewTestMap() testmap.withPar("id", 2).withPar("Name", "aiver").withPar("sex", true) fmt.Println(testmap) }
输出结果
map[Name:aiver id:2 sex:true]
标签:map,string,TestMap,withPar,testmap,interface,链式,go 来源: https://www.cnblogs.com/aiverhua/p/16223769.html