nurse/api/mux.go

30 lines
699 B
Go
Raw Permalink Normal View History

2022-05-13 13:38:19 +00:00
package api
import (
"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 {
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{
Timeout: spec.Timeout(instance.CheckTimeout),
Attempts: spec.Attempts(instance.CheckAttempts),
Check: chk,
2022-05-13 13:38:19 +00:00
})
}
return mux, nil
}