mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
* split source.Location and create source.Coordinates for minimal path addressing Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * move coordinates into separate file Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * Update syft/source/coordinates.go Co-authored-by: Dan Luhring <luhring@users.noreply.github.com>
29 lines
708 B
Go
29 lines
708 B
Go
package poweruser
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
type JSONFileContents struct {
|
|
Location source.Coordinates `json:"location"`
|
|
Contents string `json:"contents"`
|
|
}
|
|
|
|
func NewJSONFileContents(data map[source.Coordinates]string) []JSONFileContents {
|
|
results := make([]JSONFileContents, 0)
|
|
for coordinates, contents := range data {
|
|
results = append(results, JSONFileContents{
|
|
Location: coordinates,
|
|
Contents: contents,
|
|
})
|
|
}
|
|
|
|
// sort by real path then virtual path to ensure the result is stable across multiple runs
|
|
sort.SliceStable(results, func(i, j int) bool {
|
|
return results[i].Location.RealPath < results[j].Location.RealPath
|
|
})
|
|
return results
|
|
}
|