From 502fd53d06b211c23259d9ec41ade124e32e7ef1 Mon Sep 17 00:00:00 2001 From: Gardient Date: Sun, 11 Nov 2018 00:27:32 +0200 Subject: [PATCH] unmarshal json --- json.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 json.go diff --git a/json.go b/json.go new file mode 100644 index 0000000..cdfe81a --- /dev/null +++ b/json.go @@ -0,0 +1,16 @@ +package utils + +import ( + "encoding/json" + "io" + "io/ioutil" +) + +// UnmarshalJSON will unmarshal json from response body +func UnmarshalJSON(reader io.Reader, v interface{}) { + responseBody, err := ioutil.ReadAll(reader) + PanicOnError(err) + + err = json.Unmarshal(responseBody, &v) + PanicOnError(err) +}