-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
61 lines (47 loc) · 1.16 KB
/
context.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
package tensile
import (
"context"
"fmt"
"log/slog"
"github.com/ntnn/tensile/facts"
)
// TODO context should be initialized by the engine, then passed to node wrappers to fill out with e.g. the correct logger
type Context interface {
Context() context.Context
Logger() *slog.Logger
Result(Shape, string) (any, bool, error)
Facts() facts.Facts
}
var _ Context = (*TContext)(nil)
type TContext struct {
ctx context.Context
logger *slog.Logger
facts facts.Facts
}
func NewContext(ctx context.Context, logger *slog.Logger, facts facts.Facts) (*TContext, error) {
c := new(TContext)
c.ctx = ctx
if c.ctx == nil {
c.ctx = context.Background()
}
c.logger = logger
if c.logger == nil {
// TODO noop logger
c.logger = slog.Default()
}
c.facts = facts
return c, nil
}
func (ec TContext) Context() context.Context {
return ec.ctx
}
func (ec TContext) Logger() *slog.Logger {
return ec.logger
// return ec.logger.With(slog.String("identity", FormatIdentitier(ident)))
}
func (ec TContext) Result(shape Shape, name string) (any, bool, error) {
return nil, false, fmt.Errorf("not implemented")
}
func (ec TContext) Facts() facts.Facts {
return ec.facts
}