api/internal/endpoint/handler/http/mock/register.go
Peter Kurfer d70ba748f5 Introduce Lifecycle for every endpoint and manage listeners in the renamed Orchestrator
- merge packages to get a more concise layout because plugins are no more and therefore there's not a lot to be exported
- fix test logger
- rework config parsing to be easier and more transparent
- remove unnecessary APIs because dynamic endpoint handling is rather a won't implement
2021-02-10 20:26:45 +00:00

44 lines
851 B
Go

package mock
import (
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/inetmock/inetmock/internal/endpoint"
"gitlab.com/inetmock/inetmock/pkg/metrics"
)
var (
totalRequestCounter *prometheus.CounterVec
requestDurationHistogram *prometheus.HistogramVec
)
func AddHTTPMock(registry endpoint.HandlerRegistry) (err error) {
if totalRequestCounter == nil {
if totalRequestCounter, err = metrics.Counter(
name,
"total_requests",
"",
handlerNameLblName,
ruleMatchedLblName,
); err != nil {
return
}
}
if requestDurationHistogram == nil {
if requestDurationHistogram, err = metrics.Histogram(
name,
"request_duration",
"",
nil,
handlerNameLblName,
); err != nil {
return
}
}
registry.RegisterHandler(name, func() endpoint.ProtocolHandler {
return &httpHandler{}
})
return
}