witchcraft-go-server
witchcraft-go-server copied to clipboard
improvement: Server.WithHealth supports multiple calls by appending
Previously, all user-provided healthchecks must be provided in a single call to WithHealth. This has forced applications to build their own healthcheck accumulators.
I have written this code in multiple repos:
server.New().
WithInitFunc(func(ctx context.Context, info witchcraft.InitInfo) (cleanup func(), rErr error) {
var healthchecks []status.HealthCheckSource
registerHealth := func(s status.HealthCheckSource) { healthchecks = append(healthchecks, s) }
defer info.Router.WithHealth(healthchecks...)
// use registerHealth as a variable to pass to other constructors or things that produce a healthcheck
}
This behavior change is technically a break if anyone is relying on overwriting the values, but I have not been able to find and example of that use case. I considered adding a new API for this (AppendHealth?) but decided the API bloat wasn't worth it. Happy to reconsider if others disagree.