Skip to content

Instantly share code, notes, and snippets.

@edp1096
Forked from chuprik/json.go
Created August 4, 2018 16:26
Show Gist options
  • Save edp1096/54d021519b4bb52a0fae6b3c0dcbaea9 to your computer and use it in GitHub Desktop.
Save edp1096/54d021519b4bb52a0fae6b3c0dcbaea9 to your computer and use it in GitHub Desktop.
golang, echo, application/json request
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