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

golang 的 echo 有木有

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


gin.H

阅读 4.2k
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就可以了。。。

推荐问题