mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
* (perf): allow library users to skip default scanner injection Signed-off-by: Adam McClenaghan <adam@mcclenaghan.co.uk> * (perf): remove prints Signed-off-by: Adam McClenaghan <adam@mcclenaghan.co.uk> * perf: move to cataloging licenses.go Signed-off-by: adammcclenaghan <adam.mcclenaghan@upwind.io> * perf: Simplify to expose a SetContextLicenseScanner func Signed-off-by: adammcclenaghan <adam.mcclenaghan@upwind.io> --------- Signed-off-by: Adam McClenaghan <adam@mcclenaghan.co.uk> Signed-off-by: adammcclenaghan <adam.mcclenaghan@upwind.io>
26 lines
508 B
Go
26 lines
508 B
Go
package licenses
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type licenseScannerKey struct{}
|
|
|
|
var ctxKey = licenseScannerKey{}
|
|
|
|
func SetContextLicenseScanner(ctx context.Context, s Scanner) context.Context {
|
|
return context.WithValue(ctx, ctxKey, s)
|
|
}
|
|
|
|
func IsContextLicenseScannerSet(ctx context.Context) bool {
|
|
_, ok := ctx.Value(ctxKey).(Scanner)
|
|
return ok
|
|
}
|
|
|
|
func ContextLicenseScanner(ctx context.Context) (Scanner, error) {
|
|
if s, ok := ctx.Value(ctxKey).(Scanner); ok {
|
|
return s, nil
|
|
}
|
|
return NewDefaultScanner()
|
|
}
|