forked from microservices-demo/payment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiring.go
59 lines (47 loc) · 1.41 KB
/
wiring.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package payment
import (
"net/http"
"os"
"github.com/go-kit/kit/log"
"golang.org/x/net/context"
stdopentracing "github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/weaveworks/common/middleware"
)
var (
HTTPLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Help: "Time (in seconds) spent serving HTTP requests.",
Buckets: prometheus.DefBuckets,
}, []string{"method", "path", "status_code", "isWS"})
)
func init() {
prometheus.MustRegister(HTTPLatency)
}
func WireUp(ctx context.Context, declineAmount float32, tracer stdopentracing.Tracer, serviceName string) (http.Handler, log.Logger) {
// Log domain.
var logger log.Logger
{
logger = log.NewLogfmtLogger(os.Stderr)
logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC)
logger = log.NewContext(logger).With("caller", log.DefaultCaller)
}
// Service domain.
var service Service
{
service = NewAuthorisationService(declineAmount)
service = LoggingMiddleware(logger)(service)
}
// Endpoint domain.
endpoints := MakeEndpoints(service, tracer)
router := MakeHTTPHandler(ctx, endpoints, logger, tracer)
httpMiddleware := []middleware.Interface{
middleware.Instrument{
Duration: HTTPLatency,
RouteMatcher: router,
},
}
// Handler
handler := middleware.Merge(httpMiddleware...).Wrap(router)
return handler, logger
}