Publish ITWorx Pulse source
Public source validation / validate (push) Failing after 3m8s

This commit is contained in:
ITWorx Pulse release export
2026-09-03 02:09:19 +02:00
commit bd774932d5
614 changed files with 77116 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
package metricsapi
import (
"encoding/json"
"net/http"
"github.com/itworx/pulse/internal/auth"
"github.com/itworx/pulse/internal/metriccatalog"
"github.com/itworx/pulse/internal/problem"
)
type Handler struct{ Registry metriccatalog.Registry }
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet || r.URL.Path != "/api/v1/metrics/catalog" {
http.NotFound(w, r)
return
}
if _, ok := auth.PrincipalFromContext(r.Context()); !ok {
problem.Write(w, r, http.StatusUnauthorized, "UNAUTHORIZED", "Authentication required", "Authentication is required to read the metric catalog.", nil)
return
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "private, max-age=60")
w.Header().Set("ETag", `"`+h.Registry.Version()+`"`)
if r.Header.Get("If-None-Match") == `"`+h.Registry.Version()+`"` {
w.WriteHeader(http.StatusNotModified)
return
}
if err := json.NewEncoder(w).Encode(h.Registry.Response()); err != nil {
return
}
}