mirror of
https://github.com/anchore/syft.git
synced 2026-07-05 10:38:33 +02:00
Signed-off-by: anchore-oss-update-bot <anchore-oss-update-bot@users.noreply.github.com> Co-authored-by: anchore-oss-update-bot <anchore-oss-update-bot@users.noreply.github.com>
27 lines
497 B
Go
27 lines
497 B
Go
package artifact
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gohugoio/hashstructure"
|
|
)
|
|
|
|
// ID represents a unique value for each package added to a package catalog.
|
|
type ID string
|
|
|
|
type Identifiable interface {
|
|
ID() ID
|
|
}
|
|
|
|
func IDByHash(obj any) (ID, error) {
|
|
f, err := hashstructure.Hash(obj, &hashstructure.HashOptions{
|
|
ZeroNil: true,
|
|
SlicesAsSets: true,
|
|
})
|
|
if err != nil {
|
|
return "", fmt.Errorf("could not build ID for object=%+v: %w", obj, err)
|
|
}
|
|
|
|
return ID(fmt.Sprintf("%016x", f)), nil
|
|
}
|