@@ -18,18 +18,17 @@ var (
18
18
}
19
19
)
20
20
21
- // ContextInferrer is an interface used to infer the OTTL context from statements paths.
22
- type ContextInferrer interface {
23
- // Infer returns the OTTL context inferred from the given statements paths.
24
- Infer (statements []string ) (string , error )
21
+ // contextInferrer is an interface used to infer the OTTL context from statements paths.
22
+ type contextInferrer interface {
23
+ // infer returns the OTTL context inferred from the given statements paths.
24
+ infer (statements []string ) (string , error )
25
25
}
26
26
27
27
type priorityContextInferrer struct {
28
- contextPriority map [string ]int
29
- ignoreUnknownContext bool
28
+ contextPriority map [string ]int
30
29
}
31
30
32
- func (s * priorityContextInferrer ) Infer (statements []string ) (string , error ) {
31
+ func (s * priorityContextInferrer ) infer (statements []string ) (string , error ) {
33
32
var inferredContext string
34
33
var inferredContextPriority int
35
34
@@ -42,10 +41,6 @@ func (s *priorityContextInferrer) Infer(statements []string) (string, error) {
42
41
for _ , p := range getParsedStatementPaths (parsed ) {
43
42
pathContextPriority , ok := s .contextPriority [p .Context ]
44
43
if ! ok {
45
- if s .ignoreUnknownContext {
46
- continue
47
- }
48
-
49
44
// Lowest priority
50
45
pathContextPriority = math .MaxInt
51
46
}
@@ -60,26 +55,25 @@ func (s *priorityContextInferrer) Infer(statements []string) (string, error) {
60
55
return inferredContext , nil
61
56
}
62
57
63
- // DefaultPriorityContextInferrer is like NewPriorityContextInferrer , but using the default
58
+ // defaultPriorityContextInferrer is like newPriorityContextInferrer , but using the default
64
59
// context priorities and ignoring unknown/non-prioritized contexts.
65
- func DefaultPriorityContextInferrer () ContextInferrer {
66
- return NewPriorityContextInferrer (defaultContextInferPriority , false )
60
+ func defaultPriorityContextInferrer () contextInferrer {
61
+ return newPriorityContextInferrer (defaultContextInferPriority )
67
62
}
68
63
69
- // NewPriorityContextInferrer creates a new priority-based context inferrer.
64
+ // newPriorityContextInferrer creates a new priority-based context inferrer.
70
65
// To infer the context, it compares all [ottl.Path.Context] values, prioritizing them based
71
66
// on the provide contextsPriority argument, the lower the context position is in the array,
72
67
// the more priority it will have over other items.
73
68
// If unknown/non-prioritized contexts are found on the statements, they can be either ignored
74
69
// or considered when no other prioritized context is found. To skip unknown contexts, the
75
70
// ignoreUnknownContext argument must be set to false.
76
- func NewPriorityContextInferrer (contextsPriority []string , ignoreUnknownContext bool ) ContextInferrer {
71
+ func newPriorityContextInferrer (contextsPriority []string ) contextInferrer {
77
72
contextPriority := make (map [string ]int , len (contextsPriority ))
78
73
for i , ctx := range contextsPriority {
79
74
contextPriority [ctx ] = i
80
75
}
81
76
return & priorityContextInferrer {
82
- contextPriority : contextPriority ,
83
- ignoreUnknownContext : ignoreUnknownContext ,
77
+ contextPriority : contextPriority ,
84
78
}
85
79
}
0 commit comments