RequestDecoder 请求体ID解码中间件
()
| 15 | |
| 16 | // RequestDecoder 请求体ID解码中间件 |
| 17 | func RequestDecoder() gin.HandlerFunc { |
| 18 | return func(c *gin.Context) { |
| 19 | // 只处理JSON请求体 |
| 20 | // if c.GetHeader("Content-Type") != "application/json" { |
| 21 | // c.Next() |
| 22 | // return |
| 23 | // } |
| 24 | |
| 25 | // 只处理POST、PUT、PATCH请求 |
| 26 | method := c.Request.Method |
| 27 | switch method { |
| 28 | case "POST", "PUT", "PATCH", "GET", "DELETE": |
| 29 | unpdatePath(c) |
| 30 | updateQuery(c) |
| 31 | updateBody(c) |
| 32 | } |
| 33 | |
| 34 | c.Next() |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func updateBody(c *gin.Context) { |
| 39 | // 读取请求体 |
nothing calls this directly
no test coverage detected