docker-register-manager/cmd/images.go

41 lines
807 B
Go
Raw Normal View History

2024-09-30 19:31:22 +03:00
package cmd
import (
"encoding/json"
"fmt"
"gitea.stuzer.link/stuzer05/docker-registry-manager/internal/app"
"net/http"
)
func RegistryImages(app *app.App) {
type catalog struct {
Repositories []string `json:"repositories"`
}
resp, err := http.Get(app.RegistryURL + "/v2/_catalog")
if err != nil {
fmt.Println("Error fetching images:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
fmt.Println("No images found in the registry.")
return
}
var cat catalog
if err := json.NewDecoder(resp.Body).Decode(&cat); err != nil {
fmt.Println("Error decoding response:", err)
return
}
if len(cat.Repositories) == 0 {
fmt.Println("No images found in the registry.")
} else {
for _, img := range cat.Repositories {
fmt.Println(img)
}
}
}