2023-01-30 10:56:58 +02:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sync/atomic"
|
2024-03-31 00:06:25 +13:00
|
|
|
|
|
|
|
"github.com/axllent/mailpit/internal/storage"
|
2023-01-30 10:56:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ReadyzHandler is a ready probe that signals k8s to be able to retrieve traffic
|
|
|
|
func ReadyzHandler(isReady *atomic.Value) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, _ *http.Request) {
|
2024-03-31 00:06:25 +13:00
|
|
|
if isReady == nil || !isReady.Load().(bool) || storage.Ping() != nil {
|
2023-01-30 10:56:58 +02:00
|
|
|
http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
}
|
|
|
|
}
|