refactor: migrate JSON function to new package
We now use it to help read remote docker registries also.
This commit is contained in:
parent
260edad142
commit
7ad812ad98
|
@ -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,7 +1,9 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/docker/distribution/reference"
|
||||
"fmt"
|
||||
|
||||
"coopcloud.tech/abra/web"
|
||||
)
|
||||
|
||||
type Tag struct {
|
||||
|
@ -13,7 +15,13 @@ type Tags []Tag
|
|||
|
||||
var registryURL = "https://registry.hub.docker.com/v1/repositories/%s/tags"
|
||||
|
||||
func ReadRegistryTags(image reference.Named, target interface{}) ([]string, error) {
|
||||
// tagsUrl := fmt.Sprintf(registryURL, image.Name())
|
||||
return nil, nil
|
||||
func GetRegistryTags(image string) (Tags, error) {
|
||||
var tags Tags
|
||||
|
||||
tagsUrl := fmt.Sprintf(registryURL, image)
|
||||
if err := web.ReadJSON(tagsUrl, &tags); err != nil {
|
||||
return tags, err
|
||||
}
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package catalogue
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -6,7 +6,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func readJson(url string, target interface{}) error {
|
||||
// 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 {
|
Loading…
Reference in New Issue