refactor: migrate JSON function to new package

We now use it to help read remote docker registries also.
This commit is contained in:
2021-08-09 16:16:33 +02:00
parent 260edad142
commit 7ad812ad98
3 changed files with 17 additions and 7 deletions

18
web/web.go Normal file
View File

@ -0,0 +1,18 @@
package web
import (
"encoding/json"
"net/http"
"time"
)
// ReadJSON reads JSON and parses it into your chosen interface pointer
func ReadJSON(url string, target interface{}) error {
httpClient := &http.Client{Timeout: 5 * time.Second}
res, err := httpClient.Get(url)
if err != nil {
return err
}
defer res.Body.Close()
return json.NewDecoder(res.Body).Decode(target)
}