-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.go
More file actions
66 lines (52 loc) · 2.72 KB
/
Copy pathbase.go
File metadata and controls
66 lines (52 loc) · 2.72 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
package sdk
import "context"
// The Base* types below provide default implementations for the optional
// lifecycle methods of the component interfaces (Detector, Matcher, Auditor,
// Analyzer). Go interfaces have no default methods, so any method added to an
// interface is a breaking change for every implementer. Embedding a Base
// struct insulates implementations from that churn: when the SDK grows a new
// optional method, the Base type gains a sensible default and existing
// components keep compiling.
//
// Embed the Base type for your component kind and override only what you
// need:
//
// type Detector struct {
// sdk.BaseDetector
// }
//
// func (Detector) Descriptor() sdk.DetectorDescriptor { ... }
// func (Detector) PackageManagerSupport() []sdk.PackageManagerSupport { ... }
// func (Detector) ResolveGraph(ctx context.Context, req sdk.DetectionRequest) (sdk.DetectionResult, error) { ... }
//
// Identity (Descriptor) and the component's action method (ResolveGraph,
// Match, Audit, Analyze) have no meaningful default and must always be
// implemented.
// BaseDetector provides default implementations of Detector's optional
// lifecycle methods: always ready and always applicable.
type BaseDetector struct{}
// Ready reports the detector as ready.
func (BaseDetector) Ready(context.Context, DetectionRequest) error { return nil }
// Applicable reports the detector as applicable.
func (BaseDetector) Applicable(context.Context, DetectionRequest) (bool, error) { return true, nil }
// BaseMatcher provides default implementations of Matcher's optional
// lifecycle methods: always ready and always applicable.
type BaseMatcher struct{}
// Ready reports the matcher as ready.
func (BaseMatcher) Ready(context.Context, MatchRequest) error { return nil }
// Applicable reports the matcher as applicable.
func (BaseMatcher) Applicable(context.Context, MatchRequest) (bool, error) { return true, nil }
// BaseAuditor provides default implementations of Auditor's optional
// lifecycle methods: always ready and always applicable.
type BaseAuditor struct{}
// Ready reports the auditor as ready.
func (BaseAuditor) Ready(context.Context, AuditRequest) error { return nil }
// Applicable reports the auditor as applicable.
func (BaseAuditor) Applicable(context.Context, AuditRequest) (bool, error) { return true, nil }
// BaseAnalyzer provides default implementations of Analyzer's optional
// lifecycle methods: always ready and always applicable.
type BaseAnalyzer struct{}
// Ready reports the analyzer as ready.
func (BaseAnalyzer) Ready(context.Context, AnalyzeRequest) error { return nil }
// Applicable reports the analyzer as applicable.
func (BaseAnalyzer) Applicable(context.Context, AnalyzeRequest) (bool, error) { return true, nil }