From 38bf1722e564b8139c4d823bd4991574503b9fb9 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Wed, 7 Aug 2019 00:15:50 +0200 Subject: [PATCH] http: jsonrequest --- http/request.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 http/request.go diff --git a/http/request.go b/http/request.go new file mode 100644 index 0000000..5ac5171 --- /dev/null +++ b/http/request.go @@ -0,0 +1,24 @@ +package http + +import ( + "encoding/json" + "net/http" + "time" +) + +func JSONRequest(url string, value interface{}) error { + var netClient = &http.Client{ + Timeout: time.Second * 20, + } + + resp, err := netClient.Get(url) + if err != nil { + return err + } + + err = json.NewDecoder(resp.Body).Decode(&value) + if err != nil { + return err + } + return nil +}