vulncheck: add IDs to ModNode and PkgNode

This change makes ModNode and PkgNode consistent with FuncNode and
callgraph.Node upon which vulncheck graphs were modeled. This change
also helps in later CLs in that it simplifies code.

Cherry-picked: https://go-review.googlesource.com/c/exp/+/364756

Change-Id: I7b618650d054e697070aa683c326a72ac255ca44
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/395041
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/vulncheck/source.go b/vulncheck/source.go
index 28a665a..cf4961e 100644
--- a/vulncheck/source.go
+++ b/vulncheck/source.go
@@ -91,14 +91,15 @@
 	}
 
 	// Module id gets populated later.
+	id := nextPkgID()
 	pkgNode := &PkgNode{
+		ID:   id,
 		Name: pkg.Name,
 		Path: pkg.PkgPath,
 		pkg:  pkg,
 	}
 	analyzed[pkg] = pkgNode
 
-	id := nextPkgID()
 	result.Imports.Packages[id] = pkgNode
 
 	// Save node predecessor information.
@@ -197,6 +198,7 @@
 
 	id := nextModID()
 	n := &ModNode{
+		ID:      id,
 		Path:    mod.Path,
 		Version: mod.Version,
 	}
diff --git a/vulncheck/vulncheck.go b/vulncheck/vulncheck.go
index 2506045..cd9b698 100644
--- a/vulncheck/vulncheck.go
+++ b/vulncheck/vulncheck.go
@@ -128,6 +128,7 @@
 }
 
 type ModNode struct {
+	ID      int
 	Path    string
 	Version string
 	// Replace is the ID of the replacement module node, if any.
@@ -149,6 +150,7 @@
 }
 
 type PkgNode struct {
+	ID int
 	// Name is the package identifier as it appears in the source code.
 	Name string
 	Path string