Repository navigation
Expand file tree
/
Copy pathcron_config.go
More file actions
109 lines (86 loc) · 2.3 KB
/
Copy pathcron_config.go
File metadata and controls
109 lines (86 loc) · 2.3 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package micron
import (
"log/slog"
"github.com/zalgonoise/cfg"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
"github.com/zalgonoise/micron/v3/log"
"github.com/zalgonoise/micron/v3/metrics"
"github.com/zalgonoise/micron/v3/selector"
)
const (
minBufferSize = 64
defaultBufferSize = 1024
)
func defaultRuntime() *Runtime {
return &Runtime{
err: make(chan error, minBufferSize),
logger: slog.New(log.NoOp()),
metrics: metrics.NoOp(),
tracer: noop.NewTracerProvider().Tracer("micron"),
}
}
// WithSelector configures the Runtime with the input selector.Selector.
//
// This call returns a cfg.NoOp cfg.Option if the input selector.Selector is nil, or if it is a
// selector.NoOp type.
func WithSelector(sel Selector) cfg.Option[*Runtime] {
if sel == nil || sel == selector.NoOp() {
return cfg.NoOp[*Runtime]{}
}
return cfg.Register(func(r *Runtime) *Runtime {
r.sel = sel
return r
})
}
// WithErrorBufferSize defines the capacity of the error channel that the Runtime exposes in
// its Runtime.Err method.
func WithErrorBufferSize(size int) cfg.Option[*Runtime] {
if size < 0 {
size = defaultBufferSize
}
return cfg.Register(func(r *Runtime) *Runtime {
r.err = make(chan error, size)
return r
})
}
// WithMetrics decorates the Runtime with the input metrics registry.
func WithMetrics(m Metrics) cfg.Option[*Runtime] {
if m == nil {
return cfg.NoOp[*Runtime]{}
}
return cfg.Register(func(r *Runtime) *Runtime {
r.metrics = m
return r
})
}
// WithLogger configures the Runtime with the input logger.
func WithLogger(logger *slog.Logger) cfg.Option[*Runtime] {
if logger == nil {
return cfg.NoOp[*Runtime]{}
}
return cfg.Register(func(r *Runtime) *Runtime {
r.logger = logger
return r
})
}
// WithLogHandler configures the Runtime's logger using the input log handler.
func WithLogHandler(handler slog.Handler) cfg.Option[*Runtime] {
if handler == nil {
return cfg.NoOp[*Runtime]{}
}
return cfg.Register(func(r *Runtime) *Runtime {
r.logger = slog.New(handler)
return r
})
}
// WithTrace configures the Runtime with the input trace.Tracer.
func WithTrace(tracer trace.Tracer) cfg.Option[*Runtime] {
if tracer == nil {
return cfg.NoOp[*Runtime]{}
}
return cfg.Register(func(r *Runtime) *Runtime {
r.tracer = tracer
return r
})
}