-
-
Save edp1096/54d021519b4bb52a0fae6b3c0dcbaea9 to your computer and use it in GitHub Desktop.
golang, echo, application/json request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import ( | |
"encoding/json" | |
"io/ioutil" | |
"github.com/labstack/echo" | |
) | |
func BodyToJson(c echo.Context) (map[string]interface{}, error) { | |
// s, err := ioutil.ReadAll(c.Request().Body()) | |
s, err := ioutil.ReadAll(c.Request().Body) | |
if err != nil { | |
return nil, err | |
} | |
var body map[string]interface{} | |
if err := json.Unmarshal(s, &body); err != nil { | |
return nil, err | |
} | |
return body, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment