-
Notifications
You must be signed in to change notification settings - Fork 14
/
middleware.go
34 lines (26 loc) · 942 Bytes
/
middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package core
import (
"net/http"
"github.com/anz-bank/sysl-go/common"
"github.com/anz-bank/sysl-go/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type middlewareCollection struct {
admin []func(handler http.Handler) http.Handler
public []func(handler http.Handler) http.Handler
}
func prepareMiddleware(name string, promRegistry *prometheus.Registry) middlewareCollection {
result := middlewareCollection{}
result.addToBoth(Recoverer)
result.public = append(result.public, common.TraceabilityMiddleware)
result.addToBoth(common.CoreRequestContextMiddleware)
if promRegistry != nil {
metricsMiddleware := metrics.NewHTTPServerMetricsMiddleware(promRegistry, name, metrics.GetChiPathPattern)
result.addToBoth(metricsMiddleware)
}
return result
}
func (m *middlewareCollection) addToBoth(h ...func(handler http.Handler) http.Handler) {
m.admin = append(m.admin, h...)
m.public = append(m.public, h...)
}