github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/golang/cataloger.go (about) 1 /* 2 Package golang provides a concrete Cataloger implementation for go.mod files. 3 */ 4 package golang 5 6 import ( 7 "github.com/anchore/syft/internal" 8 "github.com/anchore/syft/syft/artifact" 9 "github.com/anchore/syft/syft/event/monitor" 10 "github.com/anchore/syft/syft/file" 11 "github.com/anchore/syft/syft/pkg" 12 "github.com/anchore/syft/syft/pkg/cataloger/generic" 13 ) 14 15 // NewGoModFileCataloger returns a new Go module cataloger object. 16 func NewGoModFileCataloger(opts GoCatalogerOpts) pkg.Cataloger { 17 c := goModCataloger{ 18 licenses: newGoLicenses(opts), 19 } 20 return &progressingCataloger{ 21 progress: c.licenses.progress, 22 cataloger: generic.NewCataloger("go-mod-file-cataloger"). 23 WithParserByGlobs(c.parseGoModFile, "**/go.mod"), 24 } 25 } 26 27 // NewGoModuleBinaryCataloger returns a new Golang cataloger object. 28 func NewGoModuleBinaryCataloger(opts GoCatalogerOpts) pkg.Cataloger { 29 c := goBinaryCataloger{ 30 licenses: newGoLicenses(opts), 31 } 32 return &progressingCataloger{ 33 progress: c.licenses.progress, 34 cataloger: generic.NewCataloger("go-module-binary-cataloger"). 35 WithParserByMimeTypes(c.parseGoBinary, internal.ExecutableMIMETypeSet.List()...), 36 } 37 } 38 39 type progressingCataloger struct { 40 progress *monitor.CatalogerTask 41 cataloger *generic.Cataloger 42 } 43 44 func (p *progressingCataloger) Name() string { 45 return p.cataloger.Name() 46 } 47 48 func (p *progressingCataloger) Catalog(resolver file.Resolver) ([]pkg.Package, []artifact.Relationship, error) { 49 defer p.progress.SetCompleted() 50 return p.cataloger.Catalog(resolver) 51 }