dsbifvcxr458755493 2017-07-28 07:41
浏览 39

代码在golang中做什么? [重复]

This question already has an answer here:

I tried to search this and figure out exactly how it work but I'm having trouble finding an explanation.

If i have a variable data of type interface{} (data interface{})

What would eventData := data.(map[string]interface{}) be doing? I know interface can represent a number of things, but what is a high level overview of what his happening here?

  • 写回答

1条回答 默认 最新

  • doulu4203 2017-07-28 07:50

    It is a type assertion:

    A type assertion provides access to an interface value's underlying concrete value.

    t := i.(T)


    If the asserion does not hold it will trigger a panic. To test if the value is of specific type T you can use this:

    t, ok := i.(T)

    Ok is a boolean that is true if the assertion holds and false otherwise.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 访问并爬取内容并给出完整python代码
  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥15 怎么做商品窗体,完完全全不会
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 铜与钢双金属板叠加在一起每种材料300mm长,18mm宽,4mm厚一端固定并加热至80℃,当加热端温度保持不变时另一端的稳态温度。ansys
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源