From f2ac4da8d7678c635a50e56a25d1195328208bbd Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Aug 2018 14:48:52 +0700 Subject: [PATCH] Change set value of StatusCode using reflection --- client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 735fa82..e9255e0 100644 --- a/client.go +++ b/client.go @@ -7,6 +7,8 @@ import ( "log" "net/http" "os" + "reflect" + "strconv" "time" ) @@ -106,7 +108,7 @@ func (c *Client) ExecuteRequest(req *http.Request, v interface{}) error { if err = json.Unmarshal(resBody, v); err != nil { return err } - v.(map[string]interface{})["status_code"] = string(res.StatusCode) + reflect.ValueOf(v).Elem().FieldByName("StatusCode").SetString(strconv.Itoa(res.StatusCode)) } return nil