github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/scanner/utils/utils.go (about) 1 package utils 2 3 import ( 4 "fmt" 5 6 "github.com/devseccon/trivy/pkg/fanal/types" 7 ) 8 9 // FormatVersion formats the package version based on epoch, version & release 10 func FormatVersion(pkg types.Package) string { 11 return formatVersion(pkg.Epoch, pkg.Version, pkg.Release) 12 } 13 14 // FormatSrcVersion formats the package version based on source epoch, version & release 15 func FormatSrcVersion(pkg types.Package) string { 16 return formatVersion(pkg.SrcEpoch, pkg.SrcVersion, pkg.SrcRelease) 17 } 18 19 func formatVersion(epoch int, version, release string) string { 20 v := version 21 if release != "" { 22 v = fmt.Sprintf("%s-%s", v, release) 23 } 24 if epoch != 0 { 25 v = fmt.Sprintf("%d:%s", epoch, v) 26 } 27 return v 28 29 }