1、map中interface的实现
map记得
分配内存
解析出来的int类型会变成float64类型
注意判断不为nil后再转换类型
package main
import (
"fmt"
)
func main() {
mapInterface := make(map[interface{}]interface{})
mapString := make(map[string]string)
mapInterface["k1"] = 1
mapInterface[3] = "hello"
mapInterface["world"] = 1.05
mapInterface["rt"] = true
for key, value := range mapInterface {
strKey := fmt.Sprintf("%v", key)
strValue := fmt.Sprintf("%v", value)
mapString[strKey] = strValue
}
fmt.Printf("%#v", mapString)
}
解析map中interface的值
//解析 map[string]interface{} 数据格式
func print_map(m map[string]interface{}) {
for k, v := range m {
switch value := v.(type) {
case nil:
fmt.Println(k, "is nil", "null")
case string:
fmt.Println(k, "is string", value)
case int:
fmt.Println(k, "is int", value)
case float64:
fmt.Println(k, "is float64", value)
case []interface{}:
fmt.Println(k, "is an array:")
for i, u := range value {
fmt.Println(i, u)
}
case map[string]interface{}:
fmt.Println(k, "is an map:")
print_map(value)
default:
fmt.Println(k, "is unknown type", fmt.Sprintf("%T", v))
}
}
https://blog.csdn.net/weixin_34307464/article/details/94574737
https://blog.csdn.net/weixin_30681121/article/details/95460522?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-1
2、mysql查询表
DESC 表名;
3、noce.Do函数
使用noce.Do调用时方法内执行代码只执行一次。
4、go 打印 %v %+v %#v 的区别
总结
- %v 只输出所有的值
- %+v 先输出字段类型,再输出该字段的值
- %#v 先输出结构体名字值,再输出结构体(字段类型+字段的值)