diff options
author | Ian Ling <ian@iancaling.com> | 2022-04-08 08:52:57 -0700 |
---|---|---|
committer | CatalinStratu <catalinstratu45@gmail.com> | 2022-05-05 09:38:40 +0300 |
commit | 48ae051e2d5511ba49e046bf87fa92ad62cd54d2 (patch) | |
tree | 28053dedab0877fac140c262d80133fd6f45a72c /examples/6-licensediff/example_licensediff.go | |
parent | c1d7b0ca4601ec287a997a3b9ad65da0d67b8cd5 (diff) | |
download | spdx-tools-48ae051e2d5511ba49e046bf87fa92ad62cd54d2.tar.gz |
Overhaul structs, refactor JSON parser and saver
Signed-off-by: Ian Ling <ian@iancaling.com>
Signed-off-by: CatalinStratu <catalinstratu45@gmail.com>
Diffstat (limited to 'examples/6-licensediff/example_licensediff.go')
-rw-r--r-- | examples/6-licensediff/example_licensediff.go | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/examples/6-licensediff/example_licensediff.go b/examples/6-licensediff/example_licensediff.go index 5205efa..49d7603 100644 --- a/examples/6-licensediff/example_licensediff.go +++ b/examples/6-licensediff/example_licensediff.go @@ -13,6 +13,7 @@ package main import ( "fmt" + "github.com/spdx/tools-golang/spdx" "os" "github.com/spdx/tools-golang/licensediff" @@ -85,13 +86,30 @@ func main() { // go through the first set first, report if they aren't in the second set for _, pkgID := range pkgIDsFirst { fmt.Printf("================================\n") - p1, okFirst := docFirst.Packages[pkgID] + + var p1, p2 *spdx.Package2_2 + var okFirst, okSecond bool + for _, pkg := range docFirst.Packages { + if pkg.PackageSPDXIdentifier == pkgID { + okFirst = true + p1 = pkg + break + } + } if !okFirst { fmt.Printf("Package %s has described relationship in first document but ID not found\n", string(pkgID)) continue } + fmt.Printf("Package %s (%s)\n", string(pkgID), p1.PackageName) - p2, okSecond := docSecond.Packages[pkgID] + + for _, pkg := range docSecond.Packages { + if pkg.PackageSPDXIdentifier == pkgID { + okSecond = true + p2 = pkg + break + } + } if !okSecond { fmt.Printf(" Found in first document, not found in second\n") continue @@ -121,13 +139,27 @@ func main() { // now report if there are any package IDs in the second set that aren't // in the first for _, pkgID := range pkgIDsSecond { - p2, okSecond := docSecond.Packages[pkgID] + var p2 *spdx.Package2_2 + var okFirst, okSecond bool + for _, pkg := range docSecond.Packages { + if pkg.PackageSPDXIdentifier == pkgID { + okSecond = true + p2 = pkg + break + } + } if !okSecond { fmt.Printf("================================\n") fmt.Printf("Package %s has described relationship in second document but ID not found\n", string(pkgID)) continue } - _, okFirst := docFirst.Packages[pkgID] + + for _, pkg := range docFirst.Packages { + if pkg.PackageSPDXIdentifier == pkgID { + okFirst = true + break + } + } if !okFirst { fmt.Printf("================================\n") fmt.Printf("Package %s (%s)\n", string(pkgID), p2.PackageName) |