-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
49 lines (41 loc) · 1.56 KB
/
options.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
package cloudrunner
import (
"context"
"go.einride.tech/cloudrunner/cloudconfig"
"go.einride.tech/cloudrunner/cloudtrace"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
// Option provides optional configuration for a run context.
type Option func(*runContext)
// WithRequestLoggerMessageTransformer configures the request logger with a message transformer.
// Deprecated: This was historically used for redaction. All proto messages are now automatically redacted.
func WithRequestLoggerMessageTransformer(func(proto.Message) proto.Message) Option {
return func(*runContext) {}
}
// WithConfig configures an additional config struct to be loaded.
func WithConfig(name string, config interface{}) Option {
return func(run *runContext) {
run.configOptions = append(run.configOptions, cloudconfig.WithAdditionalSpec(name, config))
}
}
// WithOptions configures the run context with a list of options.
func WithOptions(options []Option) Option {
return func(run *runContext) {
for _, option := range options {
option(run)
}
}
}
// WithGRPCServerOptions configures the run context with additional default options for NewGRPCServer.
func WithGRPCServerOptions(grpcServerOptions ...grpc.ServerOption) Option {
return func(run *runContext) {
run.grpcServerOptions = append(run.grpcServerOptions, grpcServerOptions...)
}
}
// WithTraceHook configures the run context with a trace hook.
func WithTraceHook(traceHook func(context.Context, cloudtrace.Context) context.Context) Option {
return func(run *runContext) {
run.traceMiddleware.TraceHook = traceHook
}
}