github.com/quay/claircore@v1.5.28/libvuln/driver/matcherfactory.go (about) 1 package driver 2 3 import ( 4 "context" 5 6 "net/http" 7 ) 8 9 // MatcherFactory is used to construct matchers at run-time. 10 type MatcherFactory interface { 11 Matcher(context.Context) ([]Matcher, error) 12 } 13 14 // MatcherConfigUnmarshaler can be thought of as an Unmarshal function with the byte 15 // slice provided, or a Decode function. 16 // 17 // The function should populate a passed struct with any configuration 18 // information. 19 type MatcherConfigUnmarshaler func(interface{}) error 20 21 // MatcherConfigurable is an interface that MatcherFactory can implement to opt-in to having 22 // their configuration provided dynamically. 23 type MatcherConfigurable interface { 24 Configure(context.Context, MatcherConfigUnmarshaler, *http.Client) error 25 } 26 27 // MatcherFactoryFunc would ease the registration of Matchers which don't 28 // need Configurability. 29 type MatcherFactoryFunc func(context.Context) ([]Matcher, error) 30 31 func (u MatcherFactoryFunc) Matcher(ctx context.Context) ([]Matcher, error) { 32 return u(ctx) 33 } 34 35 // MatcherStatic creates an MatcherFactoryFunc returning the provided matcher. 36 func MatcherStatic(s Matcher) MatcherFactory { 37 return MatcherFactoryFunc(func(_ context.Context) ([]Matcher, error) { 38 return []Matcher{s}, nil 39 }) 40 }