dongshang1979 2017-11-15 19:41
浏览 42
已采纳

什么是毒蛇的正确类型

I have the following yaml file and want to iterate over the cameraids.---

--- 
profiles:
  HDready: ' -vcodec libx264 -pix_fmt yuv420p -crf 23 -s 1280x720 '
  mobile: ' -vcodec libx264 -pix_fmt yuv420p -crf 23 -s 480x270 '

cameraids:
  111:
    fps: 30
  191:
    fps: 50
  851:
    fps: 50

I want now to iterate over the cameraids and profiles therefore I declare the variable for cameraids like this

var camids map[string]interface{}

The same as the fmt.Println(reflect.TypeOf(viper.Get("cameraids"))) prints but I always get the following error no new variables on left side of := when I try to get the map from viper

camids := viper.GetStringMap("cameraids")

Please can you explain and help me what I misunderstand, thanks.

  • 写回答

1条回答 默认 最新

  • drh19790711 2017-11-15 19:51
    关注

    If you've declared camids

    var camids map[string]interface{}
    

    above, you don't need to use := since the variable camids has been already declared.
    So just write:

    camids = viper.GetStringMap("cameraids")
    



    := is used when you want to declare the variable and assigns the value to it at the same time.

    = is used when you've already declared the variable beforehand and you're just assigning the value to it.

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

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办