-
Notifications
You must be signed in to change notification settings - Fork 21
/
transfer.go
executable file
·48 lines (43 loc) · 1.48 KB
/
transfer.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
package context
import (
"context"
"github.com/opentracing/opentracing-go"
http "github.com/pace/bricks/http/middleware"
"github.com/pace/bricks/http/oauth2"
"github.com/pace/bricks/locale"
"github.com/pace/bricks/maintenance/errors"
"github.com/pace/bricks/maintenance/log"
"github.com/pace/bricks/maintenance/log/hlog"
"github.com/pace/bricks/pkg/redact"
"github.com/pace/bricks/pkg/tracking/utm"
)
// Transfer takes the logger, log.Sink, authentication, request and
// error info from the given context and returns a complete
// new context with all these objects.
func Transfer(in context.Context) context.Context {
// transfer logger, log.Sink, authentication and error info
out := log.Ctx(in).WithContext(context.Background())
out = log.SinkContextTransfer(in, out)
out = oauth2.ContextTransfer(in, out)
out = errors.ContextTransfer(in, out)
out = http.ContextTransfer(in, out)
out = redact.ContextTransfer(in, out)
out = utm.ContextTransfer(in, out)
out = hlog.ContextTransfer(in, out)
out = TransferTracingContext(in, out)
return locale.ContextTransfer(in, out)
}
func TransferTracingContext(in, out context.Context) context.Context {
span := opentracing.SpanFromContext(in)
if span != nil {
out = opentracing.ContextWithSpan(out, span)
}
return out
}
func TransferExternalDependencyContext(in, out context.Context) context.Context {
edc := http.ExternalDependencyContextFromContext(in)
if edc == nil {
return out
}
return http.ContextWithExternalDependency(out, edc)
}