feat(handler): change path resolver logic
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
Piotr Icikowski 2024-02-29 01:19:31 +01:00
parent 25f3499403
commit 40bad6b345
Signed by: Piotr Icikowski
GPG Key ID: 3931CA47A91F7666

View File

@ -2,6 +2,7 @@ package kubeprobes
import ( import (
"net/http" "net/http"
"strings"
) )
type kubeprobes struct { type kubeprobes struct {
@ -11,15 +12,16 @@ type kubeprobes struct {
// ServeHTTP implements http.Handler interface // ServeHTTP implements http.Handler interface
func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path { subs := strings.Split(strings.TrimSuffix(r.URL.Path, "/"), "/")
case "/live": switch subs[len(subs)-1] {
case "live":
sq := newStatusQuery(kp.livenessProbes) sq := newStatusQuery(kp.livenessProbes)
if sq.isAllGreen() { if sq.isAllGreen() {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} else { } else {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
} }
case "/ready": case "ready":
sq := newStatusQuery(append(kp.livenessProbes, kp.readinessProbes...)) sq := newStatusQuery(append(kp.livenessProbes, kp.readinessProbes...))
if sq.isAllGreen() { if sq.isAllGreen() {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)