-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
64 lines (52 loc) · 1.55 KB
/
config.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
60
61
62
63
64
package pubsubx
import (
"bytes"
_ "embed"
"io"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
type Config struct {
Scope string `json:"scope"`
Provider string `json:"provider"`
Providers ProvidersConfig `json:"providers"`
}
type ProvidersConfig struct {
InMemory InMemoryConfig `json:"inmemory"`
Kafka KafkaConfig `json:"kafka"`
}
type InMemoryConfig struct{}
type KafkaConfig struct {
Brokers []string `json:"brokers"`
}
type pubSubOptions struct {
tracerProvider trace.TracerProvider
propagator propagation.TextMapPropagator
}
type PubSubOption func(*pubSubOptions)
// WithTracerProvider specifies a tracer provider to use for creating a tracer.
// If none is specified, no tracer is configured
func WithTracerProvider(provider trace.TracerProvider) PubSubOption {
return func(opts *pubSubOptions) {
if provider != nil {
opts.tracerProvider = provider
}
}
}
func WithPropagator(propagator propagation.TextMapPropagator) PubSubOption {
return func(opts *pubSubOptions) {
if propagator != nil {
opts.propagator = propagator
}
}
}
//go:embed config.schema.json
var ConfigSchema string
const ConfigSchemaID = "clinia://pubsub-config"
// AddConfigSchema adds the tracing schema to the compiler.
// The interface is specified instead of `jsonschema.Compiler` to allow the use of any jsonschema library fork or version.
func AddConfigSchema(c interface {
AddResource(url string, r io.Reader) error
}) error {
return c.AddResource(ConfigSchemaID, bytes.NewBufferString(ConfigSchema))
}