internal/frontend,middleware: rename to use "unit"
Rename some variables to use the term "unit".
Change-Id: Iabd5dff85f3e8163665806b27c2444ee945ff5b7
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/279455
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/frontend/latest_version.go b/internal/frontend/latest_version.go
index fd5c2d3..8a0e9cd 100644
--- a/internal/frontend/latest_version.go
+++ b/internal/frontend/latest_version.go
@@ -16,15 +16,15 @@
func (s *Server) GetLatestInfo(ctx context.Context, fullPath, modulePath string) (latest middleware.LatestInfo) {
latest.MinorVersion = s.getLatestMinorVersion(ctx, fullPath, internal.UnknownModulePath)
- latest.MajorModulePath, latest.MajorPackagePath = s.getLatestMajorVersion(ctx, fullPath, modulePath)
+ latest.MajorModulePath, latest.MajorUnitPath = s.getLatestMajorVersion(ctx, fullPath, modulePath)
return latest
}
-// getLatestMajorVersion returns the latest module path and the full package path
+// getLatestMajorVersion returns the latest module path and the full unit path
// of any major version found given the fullPath and the modulePath.
// It is intended to be used as an argument to middleware.LatestVersions.
-func (s *Server) getLatestMajorVersion(ctx context.Context, fullPath, modulePath string) (_ string, _ string) {
- latestModulePath, latestPackagePath, err := s.getDataSource(ctx).GetLatestMajorVersion(ctx, fullPath, modulePath)
+func (s *Server) getLatestMajorVersion(ctx context.Context, unitPath, modulePath string) (_ string, _ string) {
+ latestModulePath, latestPackagePath, err := s.getDataSource(ctx).GetLatestMajorVersion(ctx, unitPath, modulePath)
if err != nil {
if !errors.Is(err, derrors.NotFound) {
log.Errorf(ctx, "GetLatestMajorVersion: %v", err)
@@ -34,13 +34,13 @@
return latestModulePath, latestPackagePath
}
-// getLatestMinorVersion returns the latest minor version of the package or module.
+// getLatestMinorVersion returns the latest minor version of the unit.
// The linkable form of the minor version is returned and is an empty string on error.
// It is intended to be used as an argument to middleware.LatestVersions.
-func (s *Server) getLatestMinorVersion(ctx context.Context, packagePath, modulePath string) string {
+func (s *Server) getLatestMinorVersion(ctx context.Context, unitPath, modulePath string) string {
// It is okay to use a different DataSource (DB connection) than the rest of the
// request, because this makes a self-contained call on the DB.
- v, err := latestMinorVersion(ctx, s.getDataSource(ctx), packagePath, modulePath)
+ v, err := latestMinorVersion(ctx, s.getDataSource(ctx), unitPath, modulePath)
if err != nil {
// We get NotFound errors from directories; they clutter the log.
if !errors.Is(err, derrors.NotFound) {
@@ -54,9 +54,9 @@
// TODO(https://github.com/golang/go/issues/40107): this is currently tested in server_test.go, but
// we should add tests for this function.
-func latestMinorVersion(ctx context.Context, ds internal.DataSource, fullPath, modulePath string) (_ string, err error) {
- defer derrors.Wrap(&err, "latestMinorVersion(ctx, %q, %q)", fullPath, modulePath)
- um, err := ds.GetUnitMeta(ctx, fullPath, modulePath, internal.LatestVersion)
+func latestMinorVersion(ctx context.Context, ds internal.DataSource, unitPath, modulePath string) (_ string, err error) {
+ defer derrors.Wrap(&err, "latestMinorVersion(ctx, %q, %q)", unitPath, modulePath)
+ um, err := ds.GetUnitMeta(ctx, unitPath, modulePath, internal.LatestVersion)
if err != nil {
return "", err
}
diff --git a/internal/middleware/latestversion.go b/internal/middleware/latestversion.go
index 27dc3b9..d7f2e0d 100644
--- a/internal/middleware/latestversion.go
+++ b/internal/middleware/latestversion.go
@@ -28,12 +28,12 @@
// LatestInfo holds information about the latest versions and paths of a unit.
type LatestInfo struct {
- MinorVersion string // latest minor version for unit path, regardless of module
- MajorModulePath string // path of latest version of module
- MajorPackagePath string // path of unit in latest version of module
+ MinorVersion string // latest minor version for unit path, regardless of module
+ MajorModulePath string // path of latest version of module
+ MajorUnitPath string // path of unit in latest version of module
}
-type latestFunc func(ctx context.Context, packagePath, modulePath string) LatestInfo
+type latestFunc func(ctx context.Context, unitPath, modulePath string) LatestInfo
// LatestVersions replaces the HTML placeholder values for the badge and banner
// that displays whether the version of the package or module being served is
@@ -51,8 +51,8 @@
version = strings.Replace(version, "+", "+", -1)
modulePath := string(matches[2])
_, majorVersion, _ := module.SplitPathVersion(modulePath)
- packagePath := string(matches[3])
- latest := getLatest(r.Context(), packagePath, modulePath)
+ unitPath := string(matches[3])
+ latest := getLatest(r.Context(), unitPath, modulePath)
latestMinorClass := "DetailsHeader-badge"
switch {
case latest.MinorVersion == "":
@@ -80,7 +80,7 @@
body = bytes.ReplaceAll(body, []byte(LatestMinorVersionPlaceholder), []byte(latest.MinorVersion))
body = bytes.ReplaceAll(body, []byte(latestMajorClassPlaceholder), []byte(latestMajorClass))
body = bytes.ReplaceAll(body, []byte(LatestMajorVersionPlaceholder), []byte(latestMajorVersionText))
- body = bytes.ReplaceAll(body, []byte(LatestMajorVersionURL), []byte(latest.MajorPackagePath))
+ body = bytes.ReplaceAll(body, []byte(LatestMajorVersionURL), []byte(latest.MajorUnitPath))
}
if _, err := w.Write(body); err != nil {
log.Errorf(r.Context(), "LatestVersions, writing: %v", err)