Refactor project structure

This commit is contained in:
2024-09-30 19:31:22 +03:00
parent cb85168cbd
commit 8834dd8aec
7 changed files with 272 additions and 211 deletions

40
cmd/images.go Normal file
View File

@@ -0,0 +1,40 @@
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)
}
}
}