github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/examples/source_from_registry/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	"github.com/anchore/syft/syft"
     8  	"github.com/anchore/syft/syft/format/syftjson"
     9  )
    10  
    11  // This example demonstrates how to create an SBOM, pulling only from "registry", with error handling omitted
    12  func main() {
    13  	image := "alpine:3.19"
    14  
    15  	src, _ := syft.GetSource(context.Background(), image, syft.DefaultGetSourceConfig().WithSources("registry"))
    16  
    17  	sbom, _ := syft.CreateSBOM(context.Background(), src, syft.DefaultCreateSBOMConfig())
    18  
    19  	_ = syftjson.NewFormatEncoder().Encode(os.Stdout, *sbom)
    20  }