nurse/api/mux.go

32 lines
678 B
Go
Raw Normal View History

2022-05-13 13:38:19 +00:00
package api
import (
"net/http"
"go.uber.org/zap"
"code.1533b4dc0.de/prskr/nurse/check"
"code.1533b4dc0.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()
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),
Check: chk,
})
}
return mux, nil
}