golang echo 有木有 像 gin 一样 有个 gin.H

golang 的 echo 有木有

c.JSON(http.StatusBadRequest, gin.H{
    "status":  "error",
    "message": "创建失败",
})


gin.H

阅读 4.1k
2 个回答

type H map[string]interface{}
这个 H 就是个 map[string]interface{}

func HttpTestCtx(ctx echo.Context) error {
    return ctx.JSON(http.StatusBadRequest, map[string]interface{}{
        "status":  "error",
        "message": "创建失败",
    })
}

这样就可以了

type H map[string]interface{}
不管是gin还是echo,Json的第二个参数都是interface,你就自己将 map[string]interface{}定义成H就可以了。。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题