修改配置编辑不了的问题
This commit is contained in:
@@ -30,6 +30,7 @@ type handler struct {
|
||||
readiness Readiness
|
||||
readinessTimeout time.Duration
|
||||
healthDetails HealthDetails
|
||||
healthProvider func(context.Context) HealthDetails
|
||||
}
|
||||
|
||||
// HealthDetails contains runtime compatibility fields assembled by the
|
||||
@@ -67,6 +68,14 @@ func WithHealthDetails(details HealthDetails) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithHealthDetailsProvider evaluates mutable provider state for every health
|
||||
// request while preserving /api/health as a non-blocking liveness endpoint.
|
||||
func WithHealthDetailsProvider(provider func(context.Context) HealthDetails) Option {
|
||||
return func(h *handler) {
|
||||
h.healthProvider = provider
|
||||
}
|
||||
}
|
||||
|
||||
// NewHandler returns the foundation health/readiness HTTP handler.
|
||||
func NewHandler(readiness Readiness, options ...Option) http.Handler {
|
||||
h := &handler{readiness: readiness, readinessTimeout: defaultReadinessTimeout, healthDetails: HealthDetails{Capabilities: []any{}}}
|
||||
@@ -96,6 +105,13 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if h.readiness != nil {
|
||||
status = h.readiness.Status()
|
||||
}
|
||||
details := h.healthDetails
|
||||
if h.healthProvider != nil {
|
||||
details = h.healthProvider(r.Context())
|
||||
if details.Capabilities == nil {
|
||||
details.Capabilities = []any{}
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, struct {
|
||||
OK bool `json:"ok"`
|
||||
AppID string `json:"appId"`
|
||||
@@ -106,7 +122,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
OK: true,
|
||||
AppID: appID,
|
||||
WebOnly: true,
|
||||
HealthDetails: h.healthDetails,
|
||||
HealthDetails: details,
|
||||
Database: status,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user