-
Notifications
You must be signed in to change notification settings - Fork 8
/
factory.go
45 lines (36 loc) · 1.13 KB
/
factory.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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package postgres
import (
"context"
"go.opentelemetry.io/otel/trace"
"namespacelabs.dev/foundation/framework/resources"
"namespacelabs.dev/foundation/std/monitoring/tracing"
)
type Factory struct {
res *resources.Parsed
t trace.Tracer
}
func ProvideFactory(ctx context.Context, _ *FactoryArgs, deps ExtensionDeps) (Factory, error) {
res, err := resources.LoadResources()
if err != nil {
return Factory{}, err
}
tracer, err := tracing.Tracer(Package__sfr1nt, deps.OpenTelemetry)
if err != nil {
return Factory{}, err
}
return Factory{res, tracer}, nil
}
func (f Factory) Provide(ctx context.Context, ref string) (*DB, error) {
return ConnectToResource(ctx, f.res, ref, NewDBOptions{
Tracer: f.t,
})
}
func (f Factory) ProvideWithCustomErrors(ctx context.Context, ref string, errW func(context.Context, error) error) (*DB, error) {
return ConnectToResource(ctx, f.res, ref, NewDBOptions{
Tracer: f.t,
ErrorWrapper: errW,
})
}