internal: add DirectoryMeta
DirectoryMeta is added, which contains metadata for a directory.
This struct will be used to return the list of directories in a given
path in a follow up CL.
Change-Id: I89880bd8104791510bc07c1fb3532f6a71bed24c
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/238245
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/discovery.go b/internal/discovery.go
index 3284ae4..daccaaf 100644
--- a/internal/discovery.go
+++ b/internal/discovery.go
@@ -110,16 +110,21 @@
ModuleInfo
}
-// DirectoryNew is a folder in a module version, and all of the packages
-// inside that folder. It will replace LegacyDirectory once everything has been
-// migrated.
-type DirectoryNew struct {
+// DirectoryMeta represents a folder in a module version, and the metadata
+// associated with that folder.
+type DirectoryMeta struct {
Path string
V1Path string
IsRedistributable bool
Licenses []*licenses.Metadata // metadata of applicable licenses
- Readme *Readme
- Package *PackageNew
+}
+
+// DirectoryNew represents a folder in a module version, and the contents of that folder.
+// It will replace LegacyDirectory once everything has been migrated.
+type DirectoryNew struct {
+ DirectoryMeta
+ Readme *Readme
+ Package *PackageNew
}
// PackageNew is a group of one or more Go source files with the same package
diff --git a/internal/fetch/directory.go b/internal/fetch/directory.go
index a14364d..5901469 100644
--- a/internal/fetch/directory.go
+++ b/internal/fetch/directory.go
@@ -48,10 +48,12 @@
meta = append(meta, l.Metadata)
}
dir := &internal.DirectoryNew{
- Path: dirPath,
- V1Path: internal.V1Path(modulePath, suffix),
- IsRedistributable: isRedist,
- Licenses: meta,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: dirPath,
+ V1Path: internal.V1Path(modulePath, suffix),
+ IsRedistributable: isRedist,
+ Licenses: meta,
+ },
}
if r, ok := readmeLookup[dirPath]; ok {
dir.Readme = r
diff --git a/internal/fetch/fetchdata_test.go b/internal/fetch/fetchdata_test.go
index ff412c0..8cbea40 100644
--- a/internal/fetch/fetchdata_test.go
+++ b/internal/fetch/fetchdata_test.go
@@ -42,16 +42,20 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "github.com/basic",
- V1Path: "github.com/basic",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/basic",
+ V1Path: "github.com/basic",
+ },
Readme: &internal.Readme{
Filepath: "README.md",
Contents: "THIS IS A README",
},
},
{
- Path: "github.com/basic/foo",
- V1Path: "github.com/basic/foo",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/basic/foo",
+ V1Path: "github.com/basic/foo",
+ },
Package: &internal.PackageNew{
Name: "foo",
Documentation: &internal.Documentation{
@@ -112,16 +116,20 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "github.com/my/module",
- V1Path: "github.com/my/module",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/my/module",
+ V1Path: "github.com/my/module",
+ },
Readme: &internal.Readme{
Filepath: "README.md",
Contents: "README FILE FOR TESTING.",
},
},
{
- Path: "github.com/my/module/bar",
- V1Path: "github.com/my/module/bar",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/my/module/bar",
+ V1Path: "github.com/my/module/bar",
+ },
Readme: &internal.Readme{
Filepath: "bar/README.md",
Contents: "Another README FILE FOR TESTING.",
@@ -135,8 +143,10 @@
},
},
{
- Path: "github.com/my/module/foo",
- V1Path: "github.com/my/module/foo",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/my/module/foo",
+ V1Path: "github.com/my/module/foo",
+ },
Package: &internal.PackageNew{
Name: "foo",
Documentation: &internal.Documentation{
@@ -175,12 +185,16 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "no.mod/module",
- V1Path: "no.mod/module",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "no.mod/module",
+ V1Path: "no.mod/module",
+ },
},
{
- Path: "no.mod/module/p",
- V1Path: "no.mod/module/p",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "no.mod/module/p",
+ V1Path: "no.mod/module/p",
+ },
Package: &internal.PackageNew{
Name: "p",
Documentation: &internal.Documentation{
@@ -238,12 +252,16 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "bad.mod/module",
- V1Path: "bad.mod/module",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "bad.mod/module",
+ V1Path: "bad.mod/module",
+ },
},
{
- Path: "bad.mod/module/good",
- V1Path: "bad.mod/module/good",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "bad.mod/module/good",
+ V1Path: "bad.mod/module/good",
+ },
Package: &internal.PackageNew{
Name: "good",
Documentation: &internal.Documentation{
@@ -303,12 +321,16 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "build.constraints/module",
- V1Path: "build.constraints/module",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "build.constraints/module",
+ V1Path: "build.constraints/module",
+ },
},
{
- Path: "build.constraints/module/cpu",
- V1Path: "build.constraints/module/cpu",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "build.constraints/module/cpu",
+ V1Path: "build.constraints/module/cpu",
+ },
Package: &internal.PackageNew{
Name: "cpu",
Documentation: &internal.Documentation{
@@ -392,16 +414,20 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "nonredistributable.mod/module",
- V1Path: "nonredistributable.mod/module",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "nonredistributable.mod/module",
+ V1Path: "nonredistributable.mod/module",
+ },
Readme: &internal.Readme{
Filepath: "README.md",
Contents: "README FILE FOR TESTING.",
},
},
{
- Path: "nonredistributable.mod/module/bar",
- V1Path: "nonredistributable.mod/module/bar",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "nonredistributable.mod/module/bar",
+ V1Path: "nonredistributable.mod/module/bar",
+ },
Package: &internal.PackageNew{
Name: "bar",
Documentation: &internal.Documentation{
@@ -411,8 +437,10 @@
},
},
{
- Path: "nonredistributable.mod/module/bar/baz",
- V1Path: "nonredistributable.mod/module/bar/baz",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "nonredistributable.mod/module/bar/baz",
+ V1Path: "nonredistributable.mod/module/bar/baz",
+ },
Package: &internal.PackageNew{
Name: "baz",
Documentation: &internal.Documentation{
@@ -422,8 +450,10 @@
},
},
{
- Path: "nonredistributable.mod/module/foo",
- V1Path: "nonredistributable.mod/module/foo",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "nonredistributable.mod/module/foo",
+ V1Path: "nonredistributable.mod/module/foo",
+ },
Readme: &internal.Readme{
Filepath: "foo/README.md",
Contents: "README FILE SHOW UP HERE BUT WILL BE REMOVED BEFORE DB INSERT",
@@ -460,20 +490,28 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "bad.import.path.com",
- V1Path: "bad.import.path.com",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "bad.import.path.com",
+ V1Path: "bad.import.path.com",
+ },
},
{
- Path: "bad.import.path.com/good",
- V1Path: "bad.import.path.com/good",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "bad.import.path.com/good",
+ V1Path: "bad.import.path.com/good",
+ },
},
{
- Path: "bad.import.path.com/good/import",
- V1Path: "bad.import.path.com/good/import",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "bad.import.path.com/good/import",
+ V1Path: "bad.import.path.com/good/import",
+ },
},
{
- Path: "bad.import.path.com/good/import/path",
- V1Path: "bad.import.path.com/good/import/path",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "bad.import.path.com/good/import/path",
+ V1Path: "bad.import.path.com/good/import/path",
+ },
Package: &internal.PackageNew{
Name: "foo",
Documentation: &internal.Documentation{},
@@ -528,12 +566,16 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "doc.test",
- V1Path: "doc.test",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "doc.test",
+ V1Path: "doc.test",
+ },
},
{
- Path: "doc.test/permalink",
- V1Path: "doc.test/permalink",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "doc.test/permalink",
+ V1Path: "doc.test/permalink",
+ },
Package: &internal.PackageNew{
Name: "permalink",
Documentation: &internal.Documentation{
@@ -569,8 +611,10 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "bigdoc.test",
- V1Path: "bigdoc.test",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "bigdoc.test",
+ V1Path: "bigdoc.test",
+ },
Package: &internal.PackageNew{
Name: "bigdoc",
Documentation: &internal.Documentation{
@@ -619,17 +663,20 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "github.com/my/module/js",
- V1Path: "github.com/my/module/js",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/my/module/js",
+ V1Path: "github.com/my/module/js",
+ },
Readme: &internal.Readme{
Filepath: "README.md",
Contents: "THIS IS A README",
},
},
{
-
- Path: "github.com/my/module/js/js",
- V1Path: "github.com/my/module/js/js",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/my/module/js/js",
+ V1Path: "github.com/my/module/js/js",
+ },
Package: &internal.PackageNew{
Name: "js",
Documentation: &internal.Documentation{
@@ -674,17 +721,21 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: "std",
- V1Path: "std",
- IsRedistributable: true,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "std",
+ V1Path: "std",
+ IsRedistributable: true,
+ },
Readme: &internal.Readme{
Filepath: "README.md",
Contents: "# The Go Programming Language\n",
},
},
{
- Path: "builtin",
- V1Path: "builtin",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "builtin",
+ V1Path: "builtin",
+ },
Package: &internal.PackageNew{
Name: "builtin",
Documentation: &internal.Documentation{
@@ -693,12 +744,16 @@
},
},
{
- Path: "cmd",
- V1Path: "cmd",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "cmd",
+ V1Path: "cmd",
+ },
},
{
- Path: "cmd/pprof",
- V1Path: "cmd/pprof",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "cmd/pprof",
+ V1Path: "cmd/pprof",
+ },
Readme: &internal.Readme{
Filepath: "cmd/pprof/README",
Contents: "This directory is the copy of Google's pprof shipped as part of the Go distribution.\n",
@@ -730,8 +785,10 @@
},
},
{
- Path: "context",
- V1Path: "context",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "context",
+ V1Path: "context",
+ },
Package: &internal.PackageNew{
Name: "context",
Documentation: &internal.Documentation{
@@ -741,12 +798,16 @@
},
},
{
- Path: "encoding",
- V1Path: "encoding",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "encoding",
+ V1Path: "encoding",
+ },
},
{
- Path: "encoding/json",
- V1Path: "encoding/json",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "encoding/json",
+ V1Path: "encoding/json",
+ },
Package: &internal.PackageNew{
Name: "json",
Documentation: &internal.Documentation{
@@ -772,8 +833,10 @@
},
},
{
- Path: "errors",
- V1Path: "errors",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "errors",
+ V1Path: "errors",
+ },
Package: &internal.PackageNew{
Name: "errors",
Documentation: &internal.Documentation{
@@ -782,8 +845,10 @@
},
},
{
- Path: "flag",
- V1Path: "flag",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "flag",
+ V1Path: "flag",
+ },
Package: &internal.PackageNew{
Name: "flag",
Documentation: &internal.Documentation{
@@ -826,12 +891,16 @@
},
Directories: []*internal.DirectoryNew{
{
- Path: path,
- V1Path: path,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: path,
+ V1Path: path,
+ },
},
{
- Path: path + "/example",
- V1Path: path + "/example",
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: path + "/example",
+ V1Path: path + "/example",
+ },
Package: &internal.PackageNew{
Name: "example",
Documentation: &internal.Documentation{
diff --git a/internal/frontend/overview_test.go b/internal/frontend/overview_test.go
index 89857f5..bdb066d 100644
--- a/internal/frontend/overview_test.go
+++ b/internal/frontend/overview_test.go
@@ -63,8 +63,10 @@
name: "redistributable",
vdir: &internal.VersionedDirectory{
DirectoryNew: internal.DirectoryNew{
- Path: "github.com/u/m/p",
- IsRedistributable: true,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/u/m/p",
+ IsRedistributable: true,
+ },
Readme: &internal.Readme{
Filepath: "README.md",
Contents: "readme",
@@ -87,8 +89,10 @@
name: "unversioned",
vdir: &internal.VersionedDirectory{
DirectoryNew: internal.DirectoryNew{
- Path: "github.com/u/m/p",
- IsRedistributable: true,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/u/m/p",
+ IsRedistributable: true,
+ },
Readme: &internal.Readme{
Filepath: "README.md",
Contents: "readme",
@@ -111,8 +115,10 @@
name: "non-redistributable",
vdir: &internal.VersionedDirectory{
DirectoryNew: internal.DirectoryNew{
- Path: "github.com/u/m/p",
- IsRedistributable: false,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: "github.com/u/m/p",
+ IsRedistributable: false,
+ },
},
ModuleInfo: *sample.ModuleInfo("github.com/u/m", "v1.2.3"),
},
diff --git a/internal/postgres/directory_test.go b/internal/postgres/directory_test.go
index cc503de..c52e737 100644
--- a/internal/postgres/directory_test.go
+++ b/internal/postgres/directory_test.go
@@ -311,12 +311,14 @@
return &internal.VersionedDirectory{
ModuleInfo: *sample.ModuleInfo(modulePath, version),
DirectoryNew: internal.DirectoryNew{
- Path: path,
- V1Path: path,
- IsRedistributable: true,
- Licenses: sample.LicenseMetadata,
- Readme: readme,
- Package: pkg,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: path,
+ V1Path: path,
+ IsRedistributable: true,
+ Licenses: sample.LicenseMetadata,
+ },
+ Readme: readme,
+ Package: pkg,
},
}
}
diff --git a/internal/postgres/path_test.go b/internal/postgres/path_test.go
index 2cbd2de..051c767 100644
--- a/internal/postgres/path_test.go
+++ b/internal/postgres/path_test.go
@@ -58,7 +58,11 @@
}},
}
for d := pkgPath; d != "." && len(d) >= len(testModule.module); d = path.Dir(d) {
- dir := &internal.DirectoryNew{Path: d}
+ dir := &internal.DirectoryNew{
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: d,
+ },
+ }
if d == pkgPath {
dir.Package = &internal.PackageNew{
Path: pkgPath,
diff --git a/internal/proxydatasource/datasource.go b/internal/proxydatasource/datasource.go
index e9acc9e..de8d3f2 100644
--- a/internal/proxydatasource/datasource.go
+++ b/internal/proxydatasource/datasource.go
@@ -98,8 +98,10 @@
return &internal.VersionedDirectory{
ModuleInfo: m.ModuleInfo,
DirectoryNew: internal.DirectoryNew{
- Path: dirPath,
- V1Path: internal.V1Path(modulePath, strings.TrimPrefix(dirPath, modulePath+"/")),
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: dirPath,
+ V1Path: internal.V1Path(modulePath, strings.TrimPrefix(dirPath, modulePath+"/")),
+ },
},
}, nil
}
diff --git a/internal/testing/sample/sample.go b/internal/testing/sample/sample.go
index 2a32775..6f6af2c 100644
--- a/internal/testing/sample/sample.go
+++ b/internal/testing/sample/sample.go
@@ -216,19 +216,23 @@
func DirectoryNewEmpty(path string) *internal.DirectoryNew {
return &internal.DirectoryNew{
- Path: path,
- IsRedistributable: true,
- Licenses: LicenseMetadata,
- V1Path: path,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: path,
+ IsRedistributable: true,
+ Licenses: LicenseMetadata,
+ V1Path: path,
+ },
}
}
func DirectoryNewForModuleRoot(m *internal.LegacyModuleInfo, licenses []*licenses.Metadata) *internal.DirectoryNew {
d := &internal.DirectoryNew{
- Path: m.ModulePath,
- IsRedistributable: m.IsRedistributable,
- Licenses: licenses,
- V1Path: internal.SeriesPathForModule(m.ModulePath),
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: m.ModulePath,
+ IsRedistributable: m.IsRedistributable,
+ Licenses: licenses,
+ V1Path: internal.SeriesPathForModule(m.ModulePath),
+ },
}
if m.LegacyReadmeFilePath != "" {
d.Readme = &internal.Readme{
@@ -241,10 +245,12 @@
func DirectoryNewForPackage(pkg *internal.LegacyPackage) *internal.DirectoryNew {
return &internal.DirectoryNew{
- Path: pkg.Path,
- IsRedistributable: pkg.IsRedistributable,
- Licenses: pkg.Licenses,
- V1Path: pkg.V1Path,
+ DirectoryMeta: internal.DirectoryMeta{
+ Path: pkg.Path,
+ IsRedistributable: pkg.IsRedistributable,
+ Licenses: pkg.Licenses,
+ V1Path: pkg.V1Path,
+ },
Package: &internal.PackageNew{
Name: pkg.Name,
Path: pkg.Path,