zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[Golang系列] GOFLY在线客服-float64转uint解决interface conversion: interface {} is float64, not uint-GO语言实现开源独立部署客服系统

2023-02-18 15:36:15 时间

在使用Golang开发的过程中,要时刻注意interface{}类型本来存储的是什么类型

当需要强转回原类型时,要能转对

 

这个错误就是因为我使用gin框架的过程中,c.set()进去的类型和c.get()出来interface{}类型,强转的时候类型不对

 

c.set进去的是float64 ,我这里需要uint ,所以获取出来后需要强转成uint

    kefuId, _ := c.Get("kefu_id")
    user := &models.User{
        ID:           uint(kefuId.(float64)),
        OnlineStatus: uint(statusInt),
    }