nurse/api/mux.go
Peter Kurfer c52912c5aa
Some checks failed
agola/nurse/Test and lint The run failed
refactor: migrate to new Gitea URL
2022-09-22 11:46:36 +02:00

32 lines
728 B
Go

package api
import (
"net/http"
"go.uber.org/zap"
"code.icb4dc0.de/prskr/nurse/check"
"code.icb4dc0.de/prskr/nurse/config"
)
func PrepareMux(instance *config.Nurse, modLookup check.ModuleLookup, srvLookup config.ServerLookup) (http.Handler, error) {
mux := http.NewServeMux()
logger := zap.L()
for route, spec := range instance.Endpoints {
logger.Info("Configuring route", zap.String("route", route.String()))
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,
})
}
return mux, nil
}