File: filter.go

package info (click to toggle)
golang-github-alexliesenfeld-health 0.0~git20220920.973f6339-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 228 kB
  • sloc: makefile: 3
file content (22 lines) | stat: -rw-r--r-- 768 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package middleware

import (
	"github.com/alexliesenfeld/health"
	"net/http"
)

// FullDetailsOnQueryParam is a middleware that removes check details (such as service names, error messages, etc.)
// from the HTTP response unless the request contained a query parameter named like argument 'queryParamName'. If
// a query parameter is not present in the HTTP request, the response will only contain the aggregated health status.
func FullDetailsOnQueryParam(queryParamName string) health.Middleware {
	return func(next health.MiddlewareFunc) health.MiddlewareFunc {
		return func(r *http.Request) health.CheckerResult {
			_, fullDetails := r.URL.Query()[queryParamName]
			result := next(r)
			if !fullDetails {
				result.Details = nil
			}
			return result
		}
	}
}