2024-01-24 06:22:03 +00:00
|
|
|
package port
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-03-11 06:41:32 +00:00
|
|
|
"time"
|
2024-01-24 06:22:03 +00:00
|
|
|
|
2024-04-06 04:32:29 +00:00
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/health"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/health/healthhttp"
|
2024-01-24 06:22:03 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
)
|
|
|
|
|
2024-03-11 06:41:32 +00:00
|
|
|
const metaHandlerTimeout = 5 * time.Second
|
|
|
|
|
2024-01-24 06:22:03 +00:00
|
|
|
func NewMetaHTTPHandler(h *health.Health) http.Handler {
|
|
|
|
r := chi.NewRouter()
|
|
|
|
|
2024-03-11 06:41:32 +00:00
|
|
|
r.Use(func(next http.Handler) http.Handler {
|
|
|
|
return http.TimeoutHandler(next, metaHandlerTimeout, "Timeout")
|
|
|
|
})
|
|
|
|
|
2024-01-24 06:22:03 +00:00
|
|
|
r.Get("/livez", healthhttp.LiveHandler(h).ServeHTTP)
|
|
|
|
r.Get("/readyz", healthhttp.ReadyHandler(h).ServeHTTP)
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|