CycloneDX / cyclonedx-go

Go library to consume and produce CycloneDX Software Bill of Materials (SBOM)

Home Page:https://cyclonedx.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import Cycle Not Allowed

asponzan opened this issue · comments

I'm new to Golang so I may have missed or messed up but I'm recieving a import cycle not allowed error when trying to use this packge with the decode example

Error I'm receiving:

package command-line-arguments
        imports github.com/CycloneDX/cyclonedx-go
        imports github.com/CycloneDX/cyclonedx-go: import cycle not allowed
// main.go
package main

import (
	"fmt"
	"net/http"

	cdx "github.com/CycloneDX/cyclonedx-go"
)

func main() {
	// Acquire a BOM (e.g. by downloading it)
	res, err := http.Get("https://github.com/DependencyTrack/dependency-track/releases/download/4.1.0/bom.json")
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	// Decode the BOM
	bom := new(cdx.BOM)
	decoder := cdx.NewBOMDecoder(res.Body, cdx.BOMFileFormatJSON)
	if err = decoder.Decode(bom); err != nil {
		panic(err)
	}

	fmt.Printf("Successfully decoded BOM of %s\n", bom.Metadata.Component.PackageURL)
	fmt.Printf("- Generated: %s with %s\n", bom.Metadata.Timestamp, (*bom.Metadata.Tools.Tools)[0].Name)
	fmt.Printf("- Components: %d\n", len(*bom.Components))

}
//go.mod
module github.com/CycloneDX/cyclonedx-go

go 1.21.6

Your go.mod shouldn't be set to github.com/CycloneDX/cyclonedx-go as you want to be able to pull this library from it

I.e rename it to module example or module gitlab.com/path/to/your/repo and try again