internal: add Module.Packages

A Module.Packages() method is added, which returns all of the units for
a module that are packages.

For golang/go#258311

Change-Id: Iffb8148b1cb9ce46d3c28c74b0bfd33a06247ae3
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258338
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/discovery.go b/internal/discovery.go
index 6a347a6..cf97ed4 100644
--- a/internal/discovery.go
+++ b/internal/discovery.go
@@ -103,6 +103,17 @@
 	LegacyPackages []*LegacyPackage
 }
 
+// Packages returns all of the units for a module that are packages.
+func (m *Module) Packages() []*Unit {
+	var pkgs []*Unit
+	for _, u := range m.Units {
+		if u.IsPackage() {
+			pkgs = append(pkgs, u)
+		}
+	}
+	return pkgs
+}
+
 // IndexVersion holds the version information returned by the module index.
 type IndexVersion struct {
 	Path      string