Skip to content

Instantly share code, notes, and snippets.

@ssaumyaranjan7
Created June 9, 2019 07:39
Show Gist options
  • Save ssaumyaranjan7/b0ad8c0dec2d363d6adb2687dbe849ca to your computer and use it in GitHub Desktop.
Save ssaumyaranjan7/b0ad8c0dec2d363d6adb2687dbe849ca to your computer and use it in GitHub Desktop.
This is the utility package.
package utils
import (
"encoding/json"
"io/ioutil"
"net/http"
)
func ParseBody(r *http.Request, x interface{}) {
if body, err := ioutil.ReadAll(r.Body); err == nil {
if err := json.Unmarshal([]byte(body), x); err != nil {
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment