Created
June 9, 2019 07:39
-
-
Save ssaumyaranjan7/b0ad8c0dec2d363d6adb2687dbe849ca to your computer and use it in GitHub Desktop.
This is the utility package.
This file contains hidden or 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" | |
"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