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:
parent
260edad142
commit
7ad812ad98
@ -11,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"coopcloud.tech/abra/config"
|
"coopcloud.tech/abra/config"
|
||||||
|
"coopcloud.tech/abra/web"
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
)
|
)
|
||||||
@ -204,7 +205,7 @@ func readAppsCatalogueFS(target interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readAppsCatalogueWeb(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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/distribution/reference"
|
"fmt"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
@ -13,7 +15,13 @@ type Tags []Tag
|
|||||||
|
|
||||||
var registryURL = "https://registry.hub.docker.com/v1/repositories/%s/tags"
|
var registryURL = "https://registry.hub.docker.com/v1/repositories/%s/tags"
|
||||||
|
|
||||||
func ReadRegistryTags(image reference.Named, target interface{}) ([]string, error) {
|
func GetRegistryTags(image string) (Tags, error) {
|
||||||
// tagsUrl := fmt.Sprintf(registryURL, image.Name())
|
var tags Tags
|
||||||
return nil, nil
|
|
||||||
|
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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -6,7 +6,8 @@ import (
|
|||||||
"time"
|
"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}
|
httpClient := &http.Client{Timeout: 5 * time.Second}
|
||||||
res, err := httpClient.Get(url)
|
res, err := httpClient.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
Loading…
x
Reference in New Issue
Block a user