enhancement: use global ready and health handlers

This commit is contained in:
Florian Schade
2024-10-14 08:39:42 +02:00
committed by Christian Richter
parent 47edf8bc6d
commit c82a7c560e
33 changed files with 102 additions and 1132 deletions
+2 -18
View File
@@ -5,6 +5,7 @@ import (
"net/http"
"net/url"
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
@@ -25,7 +26,7 @@ func Server(opts ...Option) (*http.Server, error) {
debug.Pprof(options.Config.Debug.Pprof),
debug.Zpages(options.Config.Debug.Zpages),
debug.Health(health(options.Config, options.Logger)),
debug.Ready(ready(options.Config)),
debug.Ready(handlers.Ready),
), nil
}
@@ -51,20 +52,3 @@ func health(cfg *config.Config, l log.Logger) func(http.ResponseWriter, *http.Re
}
}
}
// ready implements the ready check.
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
// if we can call this function, a http(200) is a valid response as
// there is nothing we can check at this point for IDP
// if there is a mishap when initializing, there is a minimal (talking ms or ns window)
// timeframe where this code is callable
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
// io.WriteString should not fail but if it does, we want to know.
if err != nil {
panic(err)
}
}
}