These are chat archives for gin-gonic/gin

6th
Aug 2018
Liberxue
@Liberxue
Aug 06 2018 01:55
```
func Middleware() gin.HandlerFunc {
    return func(c *gin.Context) {
        var json Data
        fmt.Println(c)
        fmt.Println("Action", json.Action)
        buf := make([]byte, 1024)
        n, _ := c.Request.Body.Read(buf)
        fmt.Println(string(buf[0:n]))
        cCp := c.Copy()
        if err := c.ShouldBindJSON(&json); err == nil {
            switch json.Action {
            case "goto":
                fmt.Println(json.Action)
                TOGO(cCp)
            }
        } else {
            c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
        }

        c.Next()

    }
}

func main() {
    router := gin.Default()

    //router.POST("/", gin.WrapF(test))
    router.POST("/", Middleware())
    router.Run(":8090")
}

func TOGO(c *gin.Context) {
    fmt.Println("dsdsdsd")
    fmt.Println(c)
    var json Infos
    fmt.Println(json.Instance_id)
    buf := make([]byte, 1024)
    n, _ := c.Request.Body.Read(buf)
    fmt.Println(string(buf[0:n]))
    if err := c.BindJSON(&json); err == nil {
        fmt.Println("Action", json.Instance_id)
    }
    c.JSON(200, gin.H{
        "status":  "posted",
        "message": json.Instance_id,
    })

}
cCp := c.Copy() TOGO(cCp) Cannot pass value