forked from toolshed/abra
refactor: migrate JSON function to new package
We now use it to help read remote docker registries also.
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"coopcloud.tech/abra/config"
|
||||
"coopcloud.tech/abra/web"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
)
|
||||
@ -204,7 +205,7 @@ func readAppsCatalogueFS(target interface{}) error {
|
||||
}
|
||||
|
||||
func readAppsCatalogueWeb(target interface{}) error {
|
||||
if err := readJson(appsCatalogueURL, &target); err != nil {
|
||||
if err := web.ReadJSON(appsCatalogueURL, &target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
package catalogue
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user