func writeStatusesAsText(resp http.ResponseWriter, parts []checkStatus, unknownExcludes sets.String, failed, forceVerbose bool) {
	resp.Header().Set("Content-Type", "text/plain; charset=utf-8")
	resp.Header().Set("X-Content-Type-Options", "nosniff")
	if failed {
		resp.WriteHeader(http.StatusInternalServerError)
	} else {
		resp.WriteHeader(http.StatusOK)
	}
	if !failed && !forceVerbose {
		fmt.Fprint(resp, "ok")
		return
	}
	for _, checkOut := range parts {
		switch {
		case checkOut.excluded:
			fmt.Fprintf(resp, "[+]%s excluded: ok\n", checkOut.name)
		case checkOut.healthy:
			fmt.Fprintf(resp, "[+]%s ok\n", checkOut.name)
		default:
			fmt.Fprintf(resp, "[-]%s failed: reason withheld\n", checkOut.name)
		}
	}
	if unknownExcludes.Len() > 0 {
		fmt.Fprintf(resp, "warn: some health checks cannot be excluded: no matches for %s\n", formatQuoted(unknownExcludes.List()...))
	}
	if failed {
		log.Info("healthz check failed", "statuses", parts)
		fmt.Fprintf(resp, "healthz check failed\n")
	} else {
		fmt.Fprint(resp, "healthz check passed\n")
	}
}
writeStatusAsText writes out the given check statuses in some semi-arbitrary
bespoke text format that we copied from Kubernetes.  unknownExcludes lists
any checks that the user requested to have excluded, but weren't actually
known checks.  writeStatusAsText is always verbose on failure, and can be
forced to be verbose on success using the given argument.
package healthz
import (
	"fmt"
	"net/http"
	"path"
	"sort"
	"strings"
	"k8s.io/apimachinery/pkg/util/sets"
)
type Handler struct {
	Checks map[string]Checker
}
type checkStatus struct {
	name     string
	healthy  bool
	excluded bool
}
func (h *Handler) serveAggregated(resp http.ResponseWriter, req *http.Request) {
	failed := false
	excluded := getExcludedChecks(req)
	parts := make([]checkStatus, 0, len(h.Checks))
	for checkName, check := range h.Checks {
		if excluded.Has(checkName) {
			excluded.Delete(checkName)
			parts = append(parts, checkStatus{name: checkName, healthy: true, excluded: true})
			continue
		}
		if err := check(req); err != nil {
			log.V(1).Info("healthz check failed", "checker", checkName, "error", err)
			parts = append(parts, checkStatus{name: checkName, healthy: false})
			failed = true
		} else {
			parts = append(parts, checkStatus{name: checkName, healthy: true})
		}
	}
	if len(h.Checks) == 0 {
		parts = append(parts, checkStatus{name: "ping", healthy: true})
	}
	for _, c := range excluded.List() {
		log.V(1).Info("cannot exclude health check, no matches for it", "checker", c)
	}
	sort.Slice(parts, func(i, j int) bool { return parts[i].name < parts[j].name })
	_, forceVerbose := req.URL.Query()["verbose"]
	writeStatusesAsText(resp, parts, excluded, failed, forceVerbose)
}