LQH入职第四天(3)

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 的区别
总结

  1. %v 只输出所有的值
  2. %+v 先输出字段类型,再输出该字段的值
  3. %#v 先输出结构体名字值,再输出结构体(字段类型+字段的值)
    在这里插入图片描述
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值