doutuo6048
2016-05-10 13:57
浏览 14
已采纳

卡在我看不到的Go语法错误

I am getting a syntax error and I can't figure out why. I have tried several variations but no success.

type dataType int64

const (
    PM_SENT dataType = iota + 1
    PM_VIEWED
)

func messageHandler(m []byte) error {
    var data map[string]interface{}
    if err := json.Unmarshal(m, &data); err != nil {
        return err
    }

    var dt dataType
    flt, ok := data["type"].(float64); ok {
        dt = dataType(flt)
    }

    return nil
}

I am getting this error:

.\messageHandler.go:23: syntax error: unexpected =, expecting comma or }

Even if I change to this I still get the same error:

var dt int64
flt, ok := data["type"].(float64)
if ok {
    dt = int64(flt)
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • duanbipu1720 2016-05-12 04:18
    最佳回答

    This code doesn't throw any error:

    if flt, ok := data["type"].(float64); ok {
        dt = int64(flt)
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题