Remove CatalogMeta from CatalogEntry

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-11-22 23:19:58 +01:00
parent 331a0657ad
commit 662f340546
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 10 additions and 7 deletions

15
api.go
View file

@ -19,6 +19,13 @@ import (
"github.com/Luzifer/go-latestver/internal/fetcher"
)
type (
APICatalogEntry struct {
database.CatalogEntry
database.CatalogMeta
}
)
func buildFullURL(u *url.URL) string {
return strings.Join([]string{
strings.TrimRight(cfg.BaseURL, "/"),
@ -49,10 +56,9 @@ func handleCatalogGet(w http.ResponseWriter, r *http.Request) {
ce.Links,
fetcher.Get(ce.Fetcher).Links(&ce.FetcherConfig)...,
)
ce.CatalogMeta = *cm
w.Header().Set("Content-Type", "application/json")
if err = json.NewEncoder(w).Encode(ce); err != nil {
if err = json.NewEncoder(w).Encode(APICatalogEntry{CatalogEntry: ce, CatalogMeta: *cm}); err != nil {
log.WithError(err).Error("Unable to encode catalog entry")
http.Error(w, "Unable to encode catalog meta", http.StatusInternalServerError)
return
@ -83,7 +89,7 @@ func handleCatalogGetVersion(w http.ResponseWriter, r *http.Request) {
}
func handleCatalogList(w http.ResponseWriter, r *http.Request) {
out := make([]database.CatalogEntry, len(configFile.Catalog))
out := make([]APICatalogEntry, len(configFile.Catalog))
for i := range configFile.Catalog {
ce := configFile.Catalog[i]
@ -99,9 +105,8 @@ func handleCatalogList(w http.ResponseWriter, r *http.Request) {
ce.Links,
fetcher.Get(ce.Fetcher).Links(&ce.FetcherConfig)...,
)
ce.CatalogMeta = *cm
out[i] = ce
out[i] = APICatalogEntry{CatalogEntry: ce, CatalogMeta: *cm}
}
w.Header().Set("Content-Type", "application/json")

View file

@ -23,8 +23,6 @@ type (
CheckInterval time.Duration `json:"-" yaml:"check_interval"`
Links []CatalogLink `json:"links" yaml:"links"`
CatalogMeta `yaml:"-"`
}
CatalogLink struct {