2022-05-13 13:38:19 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2023-12-04 10:22:49 +00:00
|
|
|
"log/slog"
|
2022-05-13 13:38:19 +00:00
|
|
|
"net/http"
|
|
|
|
|
2022-09-22 09:46:36 +00:00
|
|
|
"code.icb4dc0.de/prskr/nurse/check"
|
|
|
|
"code.icb4dc0.de/prskr/nurse/config"
|
2022-05-13 13:38:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func PrepareMux(instance *config.Nurse, modLookup check.ModuleLookup, srvLookup config.ServerLookup) (http.Handler, error) {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
|
|
for route, spec := range instance.Endpoints {
|
2023-12-04 10:22:49 +00:00
|
|
|
slog.Info("Configuring route", slog.String("route", route.String()))
|
2022-05-13 13:38:19 +00:00
|
|
|
chk, err := check.CheckForScript(spec.Checks, modLookup, srvLookup)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.Handle(route.String(), CheckHandler{
|
2022-08-07 10:22:21 +00:00
|
|
|
Timeout: spec.Timeout(instance.CheckTimeout),
|
|
|
|
Attempts: spec.Attempts(instance.CheckAttempts),
|
|
|
|
Check: chk,
|
2022-05-13 13:38:19 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return mux, nil
|
|
|
|
}
|