github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/golang/cataloger.go (about) 1 /* 2 Package golang provides a concrete Cataloger implementation relating to packages within the Go language ecosystem. 3 */ 4 package golang 5 6 import ( 7 "regexp" 8 9 "github.com/anchore/syft/internal/mimetype" 10 "github.com/anchore/syft/syft/pkg" 11 "github.com/anchore/syft/syft/pkg/cataloger/generic" 12 ) 13 14 var versionCandidateGroups = regexp.MustCompile(`(?P<version>\d+(\.\d+)?(\.\d+)?)(?P<candidate>\w*)`) 15 16 const ( 17 modFileCatalogerName = "go-module-file-cataloger" 18 binaryCatalogerName = "go-module-binary-cataloger" 19 ) 20 21 // NewGoModuleFileCataloger returns a new cataloger object that searches within go.mod files. 22 func NewGoModuleFileCataloger(opts CatalogerConfig) pkg.Cataloger { 23 return generic.NewCataloger(modFileCatalogerName). 24 WithParserByGlobs(newGoModCataloger(opts).parseGoModFile, "**/go.mod") 25 } 26 27 // NewGoModuleBinaryCataloger returns a new cataloger object that searches within binaries built by the go compiler. 28 func NewGoModuleBinaryCataloger(opts CatalogerConfig) pkg.Cataloger { 29 return generic.NewCataloger(binaryCatalogerName). 30 WithParserByMimeTypes( 31 newGoBinaryCataloger(opts).parseGoBinary, 32 mimetype.ExecutableMIMETypeSet.List()..., 33 ). 34 WithResolvingProcessors(stdlibProcessor) 35 }