http: jsonrequest
continuous-integration/drone the build failed Details

This commit is contained in:
Martin/Geno 2019-08-07 00:15:50 +02:00
parent bb4d844ad2
commit 38bf1722e5
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 24 additions and 0 deletions

24
http/request.go Normal file
View File

@ -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
}